JavaScript Regular Expressions

Source: Internet
Author: User
Tags character classes

Note: in regular expressions, many punctuation marks have a special meaning. They are:

^ $ . * + ? = ! : | \ / ( ) [ ] { }

Direct-volume characters for regular expressions
character Match
Alpha-Numeric characters Their own
/ Nul character (\u0000)
\ t tab (\u0009)
\ n Line Break (\u000a)
\v Vertical tab (\U000B)
\f Page Break (\u000c)
\ r Enter (\u000d)
\xnn The Latin character specified by the hexadecimal number NN, for example, \x0a equivalent to \ n
\uxxxx The Unicode character specified by the hexadecimal XXXX, for example, \u0009 equivalent to \ t
\cx Controls the character ^x. For example, \CJ is equivalent to line break \ n

Character classes for regular expressions
character Match
[...] Any character that is within the parentheses
[^...] Any character that is not in parentheses
. Any character except newline characters and other Unicode line terminators
\w Any ASCII single character, equivalent to [a-za-z0-9_]
\w Any non-ASCII single character, equivalent to [^a-za-z0-9_]
\s Any Unicode Blank Spaces tab page break
\s Any non-Unicode whitespace characters, note that \w and \s are different
\d Any ASCII number, equivalent to [0-9_]
\d Any character other than an ASCII number, equivalent to [^0-9_]
[\b] Backspace Direct Volume (special case)

Repeating characters for regular expressions
character meaning
{N,m} Match the previous item at least n times, but not more than m times
{N,} Match the previous item n times, or more
N Match the previous item exactly n times
? Matches the previous item 0 or 1 times, which means the previous item is optional. Equivalent to {0,1}
+ Matches the previous item 1 or more times, equivalent to {1,}
* Matches the previous item 0 or more times, equivalent to {0,}

Selection, grouping, and referencing characters of regular expressions
character meaning
| Choose. Matches the subexpression to the left of the symbol or to the right sub-expression
(...) Combination. Combine several items into a single unit, which can be used by symbols such as *, +,?, and |, and you can also remember the characters that match this combination for subsequent reference use
(?:...) Combination only. Combine items into a single unit, but do not remember characters that match that group
\ n Matches the first character of the nth grouping. Groups are sub-expressions (possibly nested) in parentheses. The group number is the left-to-right count of the number of open parentheses, grouped by (?: Form does not encode

The anchor character of the regular expression
character meaning
^ Matches the beginning of a string, in a multi-row search, matches the beginning of a line
$ Matches the end of a string, in a multi-row search, matches the end of a line
\b Match the boundaries of a word. In short, it is the position between the character \w and \w, or the position between the character \w and the beginning or end of the string (but note that [\b] matches backspace)
\b Match the position of the non-word boundary
(? =p) Forward declaration, which requires the next characters to match the pattern p, but does not include those characters in the match
(?! =P) Anti-forward declaration, requiring the next character not to match the pattern p

Flags for regular expressions

character meaning
I Perform a case-insensitive match
G Performs a global match. In short, find all matches instead of stopping after finding the first one
M Multiline mode, ^ matches the beginning of a line or the beginning of a string, matches the end of a line or the end of a string

JavaScript Regular Expressions

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.