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.