When you use regular in JavaScript, you need to be aware of a hole in the bracket, which is the meta character problem in brackets. I stepped on the pit, online search and a lot of people stepped on this pit, so probably say.
The brackets are called character groups (Character Class) in the regular, some are translated into character classes , and some are translated into character sets . I think the character group is better, after all, class in the computer belongs to represent the object-oriented "class". As the name suggests, a character group is a set of characters that represents a variety of characters that may appear in one position. Note that there is only one location to match. (This paragraph is excerpted from-http://www.cnblogs.com/snandy/p/3662423.html)
Use a place to take any character, and then use the [. \n]* result Test to return true, but put it in a specific environment ... Gee, I'm going, I can't understand.
Decisively test var testp =/xx>[.\n]*/testp.test ("XX>ASDFDFASD"); To be decisive or true, it is true to put "xx>" behind, but it is false on both sides. What is this for??????
So again the var testp =/(xx>[.\n]*)/This, change the parentheses can capture the matching string . Test finished,regexp.$1 to find out is empty ... is empty .... Why????
When the string parameter of test is changed to ("..."), the string point appears, so that the middle bracket is just a point, not something else, not the meaning of a single character except \ n. So I searched the Internet:
"Many metacharacters become normal characters in a group of characters." it turned out to be a normal character, not a meta character, and other "?", "+", "*" These few once placed in the brackets also become ordinary characters.
So this hole is still to be careful ....
Yes, any character can be replaced with [\s\s].
This inventory of JavaScript regular expressions in the "pit" is a small series to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.