Counting JavaScript regular Expressions "pit" _javascript tips for middle brackets

Source: Internet
Author: User
Tags character classes

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.