Regular characters | describe |
---|---|
\ | Marks the next character as a special character, or a literal character, or a backreference, or an octal escape character. For example,"n "match character"n "。"\n "Match a newline character. Serial"\\ "match"\ "and"\( "then matches"( "。 |
^ | Matches the beginning of the input string. If the Multiline property of the RegExp object is set, ^ also matches "\n "or"\r "The position after. |
$ | Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches "\n "or"\r "Previous location. |
* | Matches the preceding subexpression zero or more times. For example, zo* matches "z "as well as"zoo ".* is equivalent to {0,}. |
+ | Matches the preceding subexpression one or more times. For example,"zo+ "can match"zo "as well as"zoo ", but cannot match"z ".+ is equivalent to {1,}. |
? | Matches the preceding subexpression zero or one time. For example,"do(es)? "can match"does "or"does "Intermediate"do ".? Equivalent to {0,1}. |
{n} | nis a non-negative integer. match confirmednSecond-rate. For example,"o{2} "cannot match"Bob "Intermediate"o ", but can match"food "The two o's in. |
{n,} | nis a non-negative integer. match at leastnSecond-rate. For example,"o{2,} "cannot match"Bob "Intermediate"o ", but can match"foooood "All the o's in."o{1,} "Equivalent to"o+ "。"o{0,} "is equivalent to"o* "。 |
{n,m} | mandnare all non-negative integers, wheren<=m. least matchntimes and matches at mostmSecond-rate. For example,"o{1,3} "will match"fooooood "The first three o's in."o{0,1} "Equivalent to"o? ". Please note that there cannot be a space between the comma and the two numbers. |
? | When this character is immediately followed by any other limiter (*, +,?, {n},{n,},{n,m}), the matching pattern is non-greedy. Non-greedy mode matches as little of the searched string as possible, while the default greedy mode matches as much of the searched string as possible. For example, for the string "oooo ","o+? "will match a single"o ",and"o+ "will match all"o "。 |
. | Match except "\ n Any single character other than ". To match includes "\ n Any characters including ", please use something like"(.|\n) "mode. |
(pattern) | Match pattern and get this match. The obtained matches can be obtained from the generated Matches collection, using the SubMatches collection in VBScript and the $0...$9 attributes in JScript. To match parentheses characters, use "\( "or"\) "。 |
(?:pattern) | Matches the pattern but does not obtain the matching result, which means that this is a non-acquisition match and is not stored for later use. This is done using the or character "(|) "Useful to combine parts of a pattern. For example"industr(?:y|ies) "It's just a comparison"industry|industries "A simpler expression. |
(?=pattern) | Forward positive lookup, matches the search string at the beginning of any string matching pattern. This is a non-fetch match, that is, the match does not need to be fetched for later use. For example,"Windows(?=95|98|NT|2000) "can match"Windows2000 "Intermediate"Windows ", but cannot match"Windows3.1 "Intermediate"Windows ". Prefetch does not consume characters, that is, after a match occurs, the search for the next match starts immediately after the last match, rather than starting after the characters containing the prefetch. |
(?!pattern) | Forward negative lookup, matches the search string at the beginning of any string that does not match the pattern. This is a non-fetch match, that is, the match does not need to be fetched for later use. For example"Windows(?!95|98|NT|2000) "can match"Windows3.1 "Intermediate"Windows ", but cannot match"Windows2000 "Intermediate"Windows ". Prefetch does not consume characters, that is, after a match occurs, the search for the next match starts immediately after the last match, rather than starting after the characters containing the prefetch |
(?<=pattern) | Reverse positive pre-checking is similar to forward positive pre-checking, but in the opposite direction. For example,"(?<=95|98|NT|2000)Windows "can match"2000Windows "Intermediate"Windows ", but cannot match"3.1Windows "Intermediate"Windows "。 |
(? | Reverse negative pre-checking is similar to forward negative pre-checking, but in the opposite direction. For example"(?"can match" |
x|y | Match x or y. For example,"z|food "can match"z "or"food "。"(z|f)ood "then matches"zood "or"food "。 |
[xyz] | Character collection. Matches any one of the characters contained. For example,"[abc] "can match"plain "Intermediate"a "。 |
[^xyz] | A collection of negative characters. Matches any character not included. For example,"[^abc] "can match"plain "Intermediate"p "。 |
[a-z] | Character range. Matches any character within the specified range. For example,"[a-z] "can match"a "arrive"z " Any lowercase alphabetic character within the range. |
[^a-z] | Negative character range. Matches any character not within the specified range. For example,"[^a-z] "can match anything that is not"a "arrive"z "Any character within the range. |
\b | Matches a word boundary, which is the position between a word and a space. For example,"er\b "can match"never "Intermediate"er ", but cannot match"verb "Intermediate"er "。 |
\B | Match non-word boundaries. "er\B "can match"verb "Intermediate"er ", but cannot match"never "Intermediate"er "。 |
\cx | Matches the control character specified by x. For example, \cM matches a Control-M or carriage return character. The value of x must be one of AZ or az. Otherwise, treat c as a literal "c "character. |
\d | Matches a numeric character. Equivalent to [0-9]. |
\D | Matches a non-numeric character. Equivalent to [^0-9]. |
\f | Matches a form feed character. Equivalent to \x0c and \cL. |
\n | Matches a newline character. Equivalent to \x0a and \cJ. |
\r | Matches a carriage return character. Equivalent to \x0d and \cM. |
\s | Matches any whitespace character, including spaces, tabs, form feeds, and so on. Equivalent to [ \f\n\r\t\v]. |
\S | Matches any non-whitespace character. Equivalent to [^ \f\n\r\t\v]. |
\t | Matches a tab character. Equivalent to \x09 and \cI. |
\v | Matches a vertical tab character. Equivalent to \x0b and \cK. |
\w | Matches any word character including an underscore. Equivalent to"[A-Za-z0-9_] "。 |
\W | Matches any non-word character. Equivalent to"[^A-Za-z0-9_] "。 |
\xn | matchn,innIs the hexadecimal escape value. The hexadecimal escape value must be exactly two digits long. For example,"\x41 "match"A "。"\x041 "is equivalent to"\x04&1 ". ASCII encoding can be used in regular expressions. |
\num | matchnum,innumis a positive integer. A reference to the match obtained. For example,"(.)\1 "matches two consecutive identical characters. |
\n | Identifies an octal escape value or a backreference. if\nbefore at leastnobtained subexpressions, thennfor backward reference. Otherwise, ifnis an octal number (0-7), thennIs an octal escape value. |
\nm | Identifies an octal escape value or a backreference. if\nmThere were at leastnmobtain subexpressions, thennmfor backward reference. if\nmThere were at leastnobtained, thennis followed by textmof backward references. If none of the previous conditions are met, ifnandmare all octal numbers (0-7), then\nmwill match octal escape valuesnm。 |
\nml | ifnis an octal number (0-3), andm and lare all octal numbers (0-7), then match the octal escape valuenml。 |
\un | matchn,innis a Unicode character represented by four hexadecimal digits. For example, \u00A9 matches the copyright symbol (©). |
username | /^[a-z0-9_-]{3,16}$/ |
---|---|
password | /^[a-z0-9_-]{6,18}$/ |
Password 2 | (?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$(Composed of numbers/uppercase letters/lowercase letters/punctuation marks, all four must be present, more than 8 digits) |
hexadecimal value | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ |
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ /^[az\d]+(\.[az\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[az] +)+$/or\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* | |
URL | /^(https?:\/\/)?([\da-z\.-]+)\.([az\.]{2,6})([\/\w \.-]*) *\/?$/ or[a-zA-z]+://[^\s]* |
IP address | /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}( ?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ or((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?) |
HTML tag | /^<([az]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/or<(.*)(.*)>.*<\/\1>|<(.*) \/> |
Remove code\\comments | (? |
Match double-byte characters (including Chinese characters) | [^\x00-\xff] |
Kanji (characters) | [\u4e00-\u9fa5] |
Chinese character range in Unicode encoding | /^[\u2E80-\u9FFF]+$/ |
Chinese and full-width punctuation marks (characters) | [\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee] |
Date (year-month-day) | (\d{4}|\d{2})-((0?([1-9]))|(1[1|2]))-((0?[1-9])|([12]([1-9]))|(3[0|1])) |
Date (month/day/year) | ((0?[1-9]{1})|(1[1|2]))/(0?[1-9]|([12][1-9])|(3[0|1]))/(\d{4}|\d{2}) |
Time (hour:minute, 24-hour format) | ((1|0?)[0-9]|2[0-3]):([0-5][0-9]) |
Mainland China landline phone number | (\d{4}-|\d{3}-)?(\d{8}|\d{7}) |
Mainland China mobile phone number | 1\d{10} |
Mainland China postal code | [1-9]\d{5} |
Mainland China ID number (15 or 18 digits) | \d{15}(\d\d[0-9xX])? |
non-negative integer (positive integer or zero) | \d+ |
positive integer | [0-9]*[1-9][0-9]* |
negative integer | -[0-9]*[1-9][0-9]* |
integer | -?\d+ |
decimal | (-?\d+)(\.\d+)? |
Blank lines | \n\s*\r or\n\n(editplus) or ^[\s\S ]*\n |
QQ number | [1-9]\d{4,} |
Words that do not contain abc | \b((?!abc)\w)+\b |
Match leading and trailing whitespace characters | ^\s*|\s*$ |
Commonly used by editors | The following are some replacements for special Chinese (editplus) ^[0-9].*\n ^[^th].*\n ^[Exercises].*\n ^[\s\S ]*\n ^[0-9]*\. ^[\s\S ]*\n *]> href="javascript:if\(confirm\('(.*?)'\)\)window\.location='(.*?)'" .[^<>]* [\s\S]*? |
Regular expression syntax is your frequently used regular expression cheat sheet, regular expression syntax query, commonly used regular expression syntax, basic regular expression syntax, subexpression syntax, regular expression modifiers, regular expression greedy mode, regular expressions Expression non-greedy mode achieves string control through a simple and fast method.