Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

regex - Javascript Regular Expression "Single Space Character"

I am learning javascript and I am analyzing existing codes.

In my JS reference book, it says to search on a single space use "s"?

But I have came across the code

obj.match(/Kobe Bryant/);

Instead of using s, it uses the actual space?

Why doesn't this generate an error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

[
vf
 u00a0u2000u2001u2002u2003u2004u2005u2006u2007u2008u2009u200au200bu2028u2029u3000]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...