我只是想了解jQuery的源代码的空白修剪REGEX和遇到以下:
rtrim = /^[suFEFFxA0]+|[suFEFFxA0]+$/g,
现在使用REGEX工具,我理解了以下内容:
/^[suFEFFxA0]+|[suFEFFxA0]+$/g
1st Alternative: ^[suFEFFxA0]+
^ assert position at start of the string
[suFEFFxA0]+ 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 [rntf ]
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: [suFEFFxA0]+$
[suFEFFxA0]+ 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 [rntf ]
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过于谨慎,因为有问题的字符已经包含在内。