Js Regular Expression

Source: Internet
Author: User
A regular expression is used to describe the content to be retrieved. 1. Create a regular expression in two ways. & Amp; nbsp; (1) implicitly create varreg =/regular/gi; & amp; nbsp; g indicates global search, and I indicates ignore size

A regular expression is used to describe the content to be retrieved.

1. Create a regular expression in two ways.

(1) implicitly create var reg =/regular/gi; g indicates global search; I indicates case-insensitive

(2) create var patt1 = new RegExp ("regular", "gi ");

2. RegExp method:

(1) The test () method is used to retrieve the value specified in the string. Returns true or false.

(2) exec () method to retrieve the value specified in the string. Returns the found value and determines its location.

3. Match values in a certain range:

[Abc] searches for any character between square brackets.

[^ Abc] searches for any characters that are not in square brackets.

[0-9] search for any number from 0 to 9.

[A-z] searches for any characters from lowercase to lowercase.

[A-Z] looks for any character from uppercase A to uppercase Z.

[A-Z] searches for any character from a to uppercase Z.

[Adgk] searches for any character in a given set.

[^ Adgk] searches for any character outside the given set.

[Red | blue | green] searches for any specified options.

4. quantifiers:

N + matches any string containing at least one n.

N * matches any string containing zero or more n.

N? Match any string containing zero or one n.

N {X} matches the string that contains X n sequences.

N {X, Y} matches the string that contains X or Y n sequences.

N {X,} matches strings that contain at least X n sequences.

N $ matches any string ending with n.

^ N matches any string starting with n.

? = N matches any string followed by the specified string n.

?! N matches any string that is not followed by the specified string n.

5. metacharacters:

. Find a single character, except for line breaks and line terminator.

\ W: Search for word characters.

\ W searches for non-word characters.

\ D.

\ D: searches for non-numeric characters.

\ S.

\ S.

\ B searches for matching at the beginning or end of a word.

\ B searches for matches that are not at the beginning or end of a word.

\ 0: Search for NUL characters.

\ N.

\ F.

\ R.

\ T.

\ V.

\ Xxx: Search for characters specified by Octal numbers xxx.

\ Xdd: Search for characters specified by dd in hexadecimal format.

\ Uxxxx searches for Unicode characters specified by the hexadecimal number xxxx.

 

 

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.