Handbook of Regular Expressions

  javascript, Regular expression

Complete set of expressions

Original link:Handbook of Regular Expressions

Character describe
\ Mark the next character as a special character, a literal character, a backward reference, or an octal escape character. For example, “n“matching character”n”。 “\n“Match a newline character. Serial “\\“Match”\“And”\(“then match”(”。
^ Matches the starting position of the input string. If setRegExpObject’sMultilineAttributes,^Also matches “\n“or”\r“After the position.
$ Matches the end position of the input string. If setRegExpObject’sMultilineAttributes,$Also matches “\n“or”\r“Before the position.
* Matches the preceding subexpression zero or more times. For example,zo*Can match “z“and”zoo”。*Equivalent to{0,}.
+ Matches the preceding subexpression one or more times. For example, “zo+“can match”zo“and”zoo“but cannot match”z”。+Equivalent to{1,}.
? Matches the preceding subexpression zero or once. For example, “do(es)?“can match”does“or”does“in”do”。?Equivalent to{0,1}.
{n} nIs a non-negative integer. MatchednTimes. For example, “o{2}“cannot match”Bob“in”o“but it matches.”food“Two of themo.
{n,} nIs a non-negative integer. At least matchnTimes. For example, “o{2,}“cannot match”Bob“in”o“but can match”foooood“All of theo. “o{1,}“Equivalent to”o+”。 “o{0,}“is equivalent to”o*”。
{n,m} mAndnAll are non-negative integers, wheren<=m. Minimum matchnSecond and Most MatchesmTimes. For example, “o{1,3}“will match”fooooood“The first threeo. “o{0,1}“Equivalent to”o?”。 Please note that there cannot be spaces between commas and numbers.
? When the character is immediately followed by any other qualifier (*,+,?,{n},{n,},{n,m}) later, the matching pattern is not greedy. The non-greedy pattern matches the searched string as little as possible, while the default greedy pattern matches the searched string as much as possible. For example, for the string “oooo”,“o+?“will match individual”o“and”o+“will match all”o”。
. Match divide “\nAny single character other than. To match include “\n“Please use characters like”(.\n)“The model.
(pattern) MatchingpatternAnd obtain this match. The obtained match may be derived from the generatedMatchesSet to get, inVBScriptUsed inSubMatchesCollection, atJScriptIn is used$0…$9Property. To match parenthesis characters, use “\(“or”|</code>”。
(? :pattern) MatchingpatternHowever, the matching result is not obtained, that is to say, it is a non-obtained match and is not stored for later use. This is using the or character “(|)“to combine various parts of a pattern is very useful. For example “industr(? :y|ies)“Is a ratio”industry|industries“A simpler expression.
(? =pattern) Positive positive pre-check, in any matchpatternMatches the lookup string at the beginning of the string for. This is a non-acquisition match, that is, the match does not need to be acquired for later use. For example, “Windows(? =95|98|NT|2000)“can match”Windows2000“in”Windows“but cannot match”Windows3.1“in”Windows”。 Pre-check does not consume characters, that is to say, after a match occurs, the search for the next match starts immediately after the last match, instead of starting after containing the pre-checked characters.
(? ! pattern) Positive negative pre-check, in any mismatchpatternMatches the lookup string at the beginning of the string for. This is a non-acquisition match, that is, the match does not need to be acquired for later use. For example “Windows(? ! 95|98|NT|2000)“can match”Windows3.1“in”Windows“but cannot match”Windows2000“in”Windows”。 Pre-check does not consume characters, that is to say, after a match occurs, the search for the next match starts immediately after the last match, instead of starting after containing the pre-checked characters.
(? <=pattern) The reverse positive pre-check is similar to the forward positive pre-check except in the opposite direction. For example, “(? <=95|98|NT|2000)Windows“can match”2000Windows“in”Windows“but cannot match”3.1Windows“in”Windows”。
(? <! pattern) The reverse negative preview is similar to the forward negative preview, but in the opposite direction. For example “(? <! 95|98|NT|2000)Windows“can match”3.1Windows“in”Windows“but cannot match”2000Windows“in”Windows”。
x|y MatchingxOry. For example, “z|food“can match”z“or”food”。 “(z|f)ood“then match”zood“or”food”。
[xyz] Character set. Matches any of the included characters. For example, “[abc]“can match”plain“in”a”。
[^xyz] A collection of negative characters. Matches any character that is not included. For example, “[^abc]“can match”plain“in”p”。
[a-z] Character range. Matches any character within the specified range. For example, “[a-z]“can match”a“To”z“range.
[^a-z] Negative character range. Matches any character that is not within the specified range. For example, “[^a-z]“Can match any absence”a“To”zAny character within the range of.
\b Match a word boundary, that is, the position between a word and a space. For example, “er\b“can match”never“in”er“but cannot match”verb“in”er”。
\B Match non-word boundaries. “er\B“can match”verb“in”er“but cannot match”never“in”er”。
\cx Match byxThe control character indicated. For example,\cMMatch oneControl-MOr carriage return.xThe value of must beA-ZOra-zOne. Otherwise, consider C as a literal “c“character.
\d Match a numeric character. Equivalent to[0-9].
\D Matches a non-numeric character. Equivalent to[^0-9].
\f Matches a page break. Equivalent to\x0cAnd\cL.
\n Matches a newline character. Equivalent to\x0aAnd\cJ.
\r Match a carriage return. Equivalent to\x0dAnd\cM.
\s Match any blank characters, including spaces, tabs, page breaks, etc. Equivalent to[\f\n\r\t\v].
\S Match any non-blank characters. Equivalent to[^\f\n\r\t\v].
\t Matches a tab character. Equivalent to\x09And\cI.
\v Matches a vertical tab. Equivalent to\x0bAnd\cK.
\w Match any word characters that include underscores. Equivalent to “[A-Za-z0-9_]”。
\W Match any non-word character. Equivalent to “[^A-Za-z0-9_]”。
\xn MatchingnOf whichnIs a hexadecimal escape value. The hexadecimal escape value must be a certain two-digit word length. For example, “\x41“Match”A”。 “\x041“is equivalent to”\x04&1”。 Can be used in regular expressionsASCIICode.
\num MatchingnumOf whichnumIs a positive integer. A reference to the obtained match. For example, “(.)\1“Matches two consecutive identical characters.
\n Identifies an octal escape value or a backward reference. If\nAt least beforenGets the subexpression, thennFor backward reference. Otherwise, ifnIs an octal number (0-7), thennIs an octal escape value.
\nm Identifies an octal escape value or a backward reference. If\nmAt least beforenmGets a subexpression, thennmFor backward reference. If\nmAt least beforenGets, thennFor a followed by textmA backward reference to the. If the preceding conditions are not met, ifnAndmAre all octal numbers (0-7), then\nmThe octal escape value will be matchednm.
\nml IfnIs an octal number (0-3), andmAndlAre all octal numbers (0-7, the octal escape value is matchednml.
\un Matchingn, of whichnIt is expressed by four hexadecimal numbersUnicodeCharacters. For example,\u00A9Match copyright symbols (©)。

Common regular expressions

Match content Regular expression
User name /^[a-z0-9_-]{3,16}$/
Password /^[a-z0-9_-]{6,18}$/
Hexadecimal value /^#? ([a-f0-9]{6}|[a-f0-9]{3})$/
E-mail /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])? )+(\.{1,2}[a-z]+)+$/
URL /^(https? :\/\/)? ([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/? $/
Ip address /((2[0-4]d|25[0-5]|[01]? dd? ).){3}(2[0-4]d|25[0-5]|[01]? dd? )/
/^(? :(? :25[0-5]|20-4|[01]? 0-9? ).){3}(? :25[0-5]|20-4|[01]? 0-9? )$/
HTML tag /^<([a-z]+)([^<]+)(?:>(.)</1>|s+/>)$/
Delete Code \ Comment (? <! http:|S)//.*$
UnicodeChinese Character Range in Coding /^[\u2E80-\u9FFF]+$/