Check [pitfalls] in the regular expressions in javascript and brackets in the regular expressions.
When using regular expressions in javascript, you need to pay attention to a pitfall in brackets, that is, the metacharacters in brackets. I stepped on the trap myself. I searched the internet and many others stepped on the trap, so I 'd like to explain it.
Brackets are called in Regular ExpressionsCharacter Group(Character class), some books are translatedCharacter class, And translateCharacter Set. I think character groups are better. After all, the class in the computer represents the "class" in the object-oriented ". As the name suggests, a character group is a group of characters, which indicate multiple characters that may appear in a single position. Note that only one location is matched here. (This section is taken from-http://www.cnblogs.com/snandy/p/3662423.html)
A place where any character is used, so the result of [. \ n] * test is used to return true, but it is not correct in the specific environment ...... I can't understand it anymore.
Decisively test var testp =/xx> [. \ n] */testp. test ("xx> asdfdfasd"); whether it is decisive or true. It is true to put "xx>" after it, but false to both sides. Why ??????
So we re-run var testp =/(Xx> [. \ n] *)/Modify it.ParenthesesYou canThe matched string is captured.. Test is complete,RegExp. $1 click it to find it is null ..... Is null ....Why ????
When the string parameter of test is changed ("........... "), this string appears, so the dot in the brackets only represents the dot, not anything else, not the meaning of a single character except \ n. So I searched the internet:
"Many characters are converted into common characters in the character group"It becomes a common character, not a metacharacter, and there are other images like "? "," + "," * ", Once put in brackets, it becomes a common character.
So be careful about this trap ....
By the way,Any character can be replaced by [\ s \ S.
The [pitfalls] in the above section of the javascript regular expression are all the content shared by the editor. I hope to give you a reference and support for the customer's home.