gpt4 book ai didi

javascript - 为什么下划线(_)不被视为非单词字符?

转载 作者:数据小太阳 更新时间:2023-10-29 05:17:28 24 4
gpt4 key购买 nike

为什么下划线(_)不被视为非单词字符?此正则表达式\W 匹配所有非单词字符但不匹配下划线。

最佳答案

引用 Jeffrey Friedl 关于正则表达式的书,这最初是对 Perl 正则表达式的更改。根据允许命名 Perl 变量的字符,回到 1988 年 [第 89 页]:

Perl 2 was released in June 1988. Larry had replaced the regex code entirely, this time using a greatly enhanced version of the Henry Spencer package mentioned in the previous section. You could still have at most nine sets of parentheses, but now you could use | inside them. Support for \d and \s was added, and support for \w was changed to include an underscore, since then it would match what characters were allowed in a Perl variable name.

关于javascript - 为什么下划线(_)不被视为非单词字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49533901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com