Javascript正则表达式“单空格字符” [英] Javascript Regular Expression "Single Space Character"
本文介绍了Javascript正则表达式“单空格字符”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习javascript而且我正在分析现有代码。
I am learning javascript and I am analyzing existing codes.
在我的JS参考书中,它说要搜索单个空格使用 \ s
?
In my JS reference book, it says to search on a single space use "\s
"?
但我遇到了代码
obj.match(/Kobe Bryant/);
而不是使用 \s
,使用实际空间?
Instead of using \s
, it uses the actual space?
为什么这不会产生错误?
Why doesn't this generate an error?
推荐答案
字符类 \s
不仅包含空格字符,还包含其他 Unicode空格字符。 \s
相当于此角色类:
The character class \s
does not just contain the space character but also other Unicode white space characters. \s
is equivalent to this character class:
[\t\n\v\f\r \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]
这篇关于Javascript正则表达式“单空格字符”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文