About Regular Expressions in JS (2)

Source: Internet
Author: User
Tags control characters printable characters

Special Character and character match

Special characters

\ Xn matches a character whose ASCII value is equal to n, and n must be two charactersHexadecimal integer. For example, \ x41 matches the character "". It can indicate all non-printable characters.

\ N here n is a one-digitOctal0-7 ). If at least n matched sub-captures exist before \ n, \ n is a reverse reference.

\ Nm is where m and n are both oneOctal0-7 ). If at least n matched subcaptures exist before \ mn, \ mn is a reverse reference.

\ Nm1: WHEN n is octal 0-3), m and 1 are octal 0-7), the matching ASCII code value is equivalent to nml characters of octal.

\ Un matches the character whose Unicoe encoding is equal to n. N must be4-digit hexadecimal integer. For example, \ u00A9 matches the copyright symbol.

\ Cx matches the control characters specified by x. For example, \ cM matches the control character indicated by Ctrl + M, that is, the carriage return. The value of X must be between the A-Z or a-z, otherwise c is the literal character "c"

Character matching character

[...] Match any character in the character set contained in square brackets. For example, [abc] can match any one of the characters a, B, and c3. If the character set must contain] characters, you must put it first, that is, followed. To include \ in [...], use \\.

[^...] Any character not included in square brackets. For example, [^ abc] can match any character other than a, B, c, and 3 characters.

[A-z] matches any character in any specified range. For example, [1-9] matches any number characters between 1-9. To include a hyphen-in square brackets, you can use "\" to mark it as a literal character, for example, [a \-z], [-a-z], or [a-z-].

[^ A-z] matches any character that is not within the specified range.

\ D matches any number character

\ D matches any non-Numeric Character

\ S matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v]

\ S matches any non-blank characters

\ W matches any English letters, numbers, and underlines

\ W matches any non-English letters and numbers, but does not contain underscores

. Match any single character except \ n. Example: (.) \ 1 matches two consecutive identical characters except \ n

Positioning operator and literal character

Location Operator Used for text Verification

Use ^ to match the start position of the target string. It is also used for the first row match, that is, it matches the position after \ n and \ r.

Use $ to match the end position of the target string, or use it to match the end of the row.

\ B matches a word boundary, including the position between the word and the space, and the start and end position of the target string. For example, er \ B matches the er in neverok and does not match the er in verb.

\ B match non-character Boundary

Escape special characters

Some metacharacters used in the expression do not represent the original literal meaning. Match the metacharacters with special literal meanings and use "\" to convert the characters to the original literal characters. The escape types include "$", "(", ")", "*", ".", "[", "]", "?", "\", "/", "^" "{" "}" |"

This article is from the "yuhuifei" blog, please be sure to keep this source http://4745272.blog.51cto.com/4735272/1297958

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.