JavaScript 中的 $ 符号
在 JavaScript 中,$ 符号是一个通配符,表示任何字符串。它经常用于匹配任何字符或字符序列,从而使正则表达式更简洁、更通用。
用法
$ 符号通常用在正则表达式的末尾,它会匹配输入字符串末尾的任何字符或字符序列。例如:
<code class="javascript">const regex = /s$/; const string = "this"; const match = regex.test(string); // true const regex2 = /(.)$/; const string2 = "hello"; const match2 = regex2.test(string2); // true</code>