谁能解释一下下面的示例代码? 它来自最后一个例子 here .
不知道为什么在 '.'
之前没有 '\'
,可以通过添加 '\'
.
JavaScript:
var url = "http://xxx.domain.com";
print(/[^.]+/.exec(url)[0].substr(7)); // prints "xxx"
最佳答案
注意段落here关于字符类中的元字符
Note that the only special characters or metacharacters inside a character class are the closing bracket (]), the backslash (\), the caret (^) and the hyphen (-). The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash.
关于javascript - 任何人都可以解释以下 javascript RE 代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18118065/