| Regex characters | Description |
|---|---|
| \ | Marks the next character as a special character, a literal, a backreference or an octal escape. For example, “n"match a character"n"。"\n"Matches a newline character. Sequential"\\"match"\"而"\("then match("。 |
| ^ | Matches the beginning of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after “\n"or"\r"position after it. |
| $ | Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches the position before “\n"or"\r"position before it. |
| * | 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+"matches"zo"and"zoo", but does not match "z".+ equivalent to{1,}。 |
| ? | Matches the preceding subexpression zero or one time. For example, “do(es)?"can match"does"or"does" in "do".? equivalent to{0,1}。 |
| {n} | nis a non-negative integer. Matches the specifiedn times. For example, “o{2}"cannot match"Bob" in "o", but it can match"food"two o's in it. |
| {n,} | nis a non-negative integer. Matches at leastn times. For example, “o{2,}"cannot match"Bob" in "o", but can match"foooood"all the o's in it."o{1,}"equivalent to"o+"。"o{0,}then equivalent too*"。 |
| {n,m} | mAndnare all non-negative integers, wheren<=m.最少匹配ntimes and match at mostm times. For example, “o{1,3}"will match"fooooood"the first three o's in it."o{0,1}"equivalent to"o?". Note that there must be no space between the comma and the two numbers. |
| ? | When this character immediately follows any other quantifier (*, +, ?,{n},{n,},{n,m}) the matching mode is non-greedy. A non-greedy mode matches as few of the searched string as possible, while the default greedy mode matches as many as possible. For example, for the string “oooo","o+?"will match a single"o",而"o+"will match all"o"。 |
| . | Match except “\n"Any single character other than. To match including"\nany character, including the ", use something like "(.|\n)" pattern. |
| (pattern) | Matches pattern and captures this match. The captured match can be retrieved from the resulting Matches collection; in VBScript use the SubMatches collection, and in JScript use the $0…$9 properties. To match a parenthesis character, use “\("or"\)"。 |
| (?:pattern) | Matches pattern without getting the matched result, that is, this is a non-capturing match and nothing is stored for later use. This is used with the or character “(|)" is very useful for combining the parts of a pattern. For exampleindustr(?:y|ies)"is just one exampleindustry|industries"a more concise expression. |
| (?=pattern) | Positive lookahead matches the search string at any position where the string matches pattern. This is a non-capturing match, that is, the match is not retrieved for later use. For example, “Windows(?=95|98|NT|2000)"matches"Windows2000" in "Windows", but does not match "Windows3.1" in "Windows". A lookahead does not consume characters, that is, after a match is found the search for the next match starts immediately after the last match, not after the characters included in the lookahead. |
| (?!pattern) | Negative lookahead matches the search string at any position where the string does not match pattern. This is a non-capturing match, that is, the match is not retrieved for later use. For example “Windows(?!95|98|NT|2000)"matches"Windows3.1" in "Windows", but does not match "Windows2000" in "Windows". A lookahead does not consume characters, that is, after a match is found the search for the next match starts immediately after the last match, not after the characters included in the lookahead |
| (?<=pattern) | Positive lookbehind, similar to positive lookahead, but in the opposite direction. For example, “(?<=95|98|NT|2000)Windows"matches"2000Windows" in "Windows", but does not match "3.1Windows" in "Windows"。 |
| (?<!pattern) | Negative lookbehind, similar to negative lookahead, but in the opposite direction. For example “(?<!95|98|NT|2000)Windows"matches"3.1Windows" in "Windows", but does not match "2000Windows" in "Windows"。 |
| x|y | Match x or y. For example, “z|food"matches"z"or"food"。"(z|f)ood"then matchzood"or"food"。 |
| [xyz] | Character set. Matches any one of the characters included. For example, “[abc]"can match"plain" in "a"。 |
| [^xyz] | Negated character set. Matches any character not included. For example, “[^abc]"can match"plain" in "p"。 |
| [a-z] | Character range. Matches any character in the specified range. For example, “[a-z]"can match"a"to"zany lowercase letter in the " range. |
| [^a-z] | Negated character range. Matches any character not in the specified range. For example, “[^a-z]"can match anything not in"a"to"z"any character in the range. |
| \b | Matches a word boundary, that is, the position between a word and a space. For example, “er\b"can match"never" in "er", but does not match "verb" in "er"。 |
| \B | Match a non-word boundary. “er\B"matches"verb" in "er", but does not match "never" in "er"。 |
| \cx | Matches the control character specified by x. For example, \cM matches a Control-M or carriage return. The value of x must be A-Z or a-z. Otherwise, c is treated as a literal “c"字元. |
| \d | Matches a digit. Equivalent to [0-9]. |
| \D | Matches a non-digit character. Equivalent to [^0-9]. |
| \f | Matches a form feed. Equivalent to \x0c and \cL. |
| \n | Matches a line feed. Equivalent to \x0a and \cJ. |
| \r | Matches a carriage return. Equivalent to \x0d and \cM. |
| \s | Matches any whitespace character, including spaces, tabs, form feeds, etc. Equivalent to [ \f\n\r\t\v]. |
| \S | Matches any non-whitespace character. Equivalent to [^ \f\n\r\t\v]. |
| \t | Matches a tab. Equivalent to \x09 and \cI. |
| \v | Matches a vertical tab. Equivalent to \x0b and \cK. |
| \w | Matches any word character including the underscore. Equivalent to “[A-Za-z0-9_]"。 |
| \W | Match any non-word character. Equivalent to “[^A-Za-z0-9_]"。 |
| \xn | Matchn, wherenMarks a hexadecimal escape value, which must be exactly two digits long. For example, “\x41"match"A"。"\x041then equivalent to\x04&1". Regular expressions can use ASCII encoding. |
| \num | Matchnum, wherenumIs a positive integer. A reference to the match obtained. For example, “(.)\1"Matches two consecutive identical characters. |
| \n | Marks an octal escape value or a backreference. If \nAt least beforencaptured subexpressions, thennis a backreference. Otherwise, ifnis an octal digit (0-7), thennis an octal escape value. |
| \nm | Marks an octal escape value or a backreference. If \nmat least beforenmobtained subexpressions, thennmis a backreference. If \nmat least beforen個獲取,則nfor one followed by textmbackreference. If none of the previous conditions match, ifnAndmare all octal digits (0-7), then \nmwill match the octal escape valuenm。 |
| \nml | Ifnis an octal digit (0-3), andm and lall are octal digits (0-7), it matches the octal escape valuenml。 |
| \un | Matchn, wherenMatches a Unicode character specified 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).*$ (digits/uppercase/lowercase/punctuation, all four required, 8 or more characters) |
| Hexadecimal value | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ |
| /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/ or\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* | |
| URL | /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ 或 [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]?)$/ 或 ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?) |
| HTML tags | /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ or<(.*)(.*)>.*<\/\1>|<(.*) \/> |
| Remove code\\comments | (?<!http:|\S)//.*$ |
| Matches double-byte characters (including Han characters) | [^\x00-\xff] |
| Chinese characters (characters) | [\u4e00-\u9fa5] |
| Range of Chinese characters in Unicode encoding | /^[\u2E80-\u9FFF]+$/ |
| Chinese characters and full-width punctuation (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 clock) | ((1|0?)[0-9]|2[0-3]):([0-5][0-9]) |
| Mainland China landline number | (\d{4}-|\d{3}-)?(\d{8}|\d{7}) |
| Mainland China mobile number | 1\d{10} |
| Mainland China postal code | [1-9]\d{5} |
| Mainland China ID card 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 (1.x) | -?\d+ |
| Decimal (0.x) | (-?\d+)(\.\d+)? |
| Blank line | \n\s*\r 或者 \n\n(editplus) 或者 ^[\s\S ]*\n |
| QQ number | [1-9]\d{4,} |
| Words not containing abc | \b((?!abc)\w)+\b |
| Match leading/trailing whitespace | ^\s*|\s*$ |
| Edit favorites | Below are some replacements for special Chinese characters (editplus) ^[0-9].*\n ^[^第].*\n ^[習題].*\n ^[\s\S ]*\n ^[0-9]*\. ^[\s\S ]*\n <p[^<>*]> href="javascript:if\(confirm\('(.*?)'\)\)window\.location='(.*?)'" <span style=".[^"]*rgb\(255,255,255\)">.[^<>]*</span> <DIV class=xs0>[\s\S]*?</DIV> |
The regular expression syntax page is a quick reference for common regex, covering regex syntax lookup, basic syntax, subexpression syntax, modifiers and greedy and non-greedy modes, letting you control strings with simple, fast methods.
This tool belongs to the “Code & markup formatting” category.
Your input is processed locally in the browser whenever possible. We do not store it.
Formatting expands code into indented lines for readability; minifying strips whitespace and comments to reduce size.
Only whitespace, line breaks and comments are touched. With JavaScript that relies on automatic semicolon insertion, test the minified output before shipping.
Formatting and minifying run client-side. Nothing is written to server logs.