在jQuery源码中理解空格正则表达式
Understanding whitespace regex in jQuery source
我只是想了解jQuery的源代码的空白修剪REGEX和遇到以下:
rtrim = /^['s'uFEFF'xA0]+|['s'uFEFF'xA0]+$/g,
现在使用REGEX工具,我理解了以下内容:
/^['s'uFEFF'xA0]+|['s'uFEFF'xA0]+$/g
1st Alternative: ^['s'uFEFF'xA0]+
^ assert position at start of the string
['s'uFEFF'xA0]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
's match any white space character ['r'n't'f ]
'uFEFF matches the character uFEFF literally (case sensitive)
'xA0 matches the character with position 0xA0 (160 decimal or 240 octal) in the character set
2nd Alternative: ['s'uFEFF'xA0]+$
['s'uFEFF'xA0]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
's match any white space character ['r'n't'f ]
'uFEFF matches the character uFEFF literally (case sensitive)
'xA0 matches the character with position 0xA0 (160 decimal or 240 octal) in the character set
$ assert position at end of the string
g modifier: global. All matches (don't return on first match)
上面的描述使REGEX非常容易理解,但仍然考虑实际实现,一些事情没有意义,即
uFEFF
为什么一个字符会有这个字符,它和空白有什么关系?xA0
到底是什么?
谁能解释一下?你不必给出最详细的答案,简短的回答就可以了。
0xFEFF
被称为ZERO WIDTH NO-BREAK SPACE,并且可能不会在某些浏览器上单独使用's
。0x00A0
也一样,没有空格
关于's
在ECMA 262 (Javascript的标准)中捕获的更多细节,请参阅本文档。根据该规范,jQuery过于谨慎,因为有问题的字符已经包含在内。
相关文章:
- 正则表达式搜索一个空格,后跟一个字符
- 较短的正则表达式,按2个条件拆分,外部有空格
- 正则表达式,用于去掉逗号后的单个空格
- 正则表达式允许字母数字和空格,但不允许连续两个空格
- 正则表达式和 javascript:匹配数字后跟空格和大写字母之间的所有内容
- 正则表达式匹配空白或空格 JavaScript
- 字符串替换正则表达式,开头为空格
- 如何在正则表达式中匹配空格、换行符
- 为什么当我在正则表达式中放置空格键时,我的 Javascript test() 函数失败了
- 用于匹配带空格和不带空格的多个单词的正则表达式
- 正则表达式,用于除所有空格和一个特殊字符之外的所有内容
- 使用正则表达式获取多个单词,单词之间留有空格
- 如何使正则表达式接受ONLY字母表和空格
- Javascript正则表达式,返回连字符和空格后面的数字
- JS正则表达式匹配单词,包括用空格括起来的单词
- 需要帮助设计正则表达式来选择'|'和'|'如果第一个'|'后面跟着一个空格
- 在搜索表单中,替换空格或仅使用正则表达式的隐词和数字
- 在jQuery源码中理解空格正则表达式
- 带有空格正则表达式的字母数字
- 字母数字,破折号和下划线,但没有空格正则表达式检查JavaScript