| Description | Regular expression |
|---|---|
| URL | [a-zA-z]+://[^\s]* |
| IP address (IP Address) | ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?) |
| Email address | \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* |
| QQ number | [1-9]\d{4,} |
| HTML tag (contains content or self-closing) | <(.*)(.*)>.*<\/\1>|<(.*) \/> |
| Password (digits/uppercase/lowercase/punctuation, all four required, 8 or more characters) | (?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$ |
| Date (year-month-day) | (\d{4}|\d{2})-((1[0-2])|(0?[1-9]))-(([12][0-9])|(3[01])|(0?[1-9])) |
| Date (month/day/year) | ((1[0-2])|(0?[1-9]))/(([12][0-9])|(3[01])|(0?[1-9]))/(\d{4}|\d{2}) |
| Time (hour:minute, 24-hour clock) | ((1|0?)[0-9]|2[0-3]):([0-5][0-9]) |
| Chinese characters (characters) | [\u4e00-\u9fa5] |
| Chinese characters and full-width punctuation (characters) | [\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee] |
| 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+)? |
| Words not containing abc | \b((?!abc)\w)+\b |
| Description | Regular expression |
|---|---|
| Username | /^[a-z0-9_-]{3,16}$/ |
| Password | /^[a-z0-9_-]{6,18}$/ |
| Hexadecimal value | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ |
| /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ | |
| URL | /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ |
| IP address | /^(?:(?: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]?)$/ |
| HTML tags | /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ |
| Range of Chinese characters in Unicode encoding | /^[u4e00-u9fa5],{0,}$/ |
| Regex for matching Chinese characters | [\u4e00-\u9fa5] |
| Note: matching Chinese is really a headache; this expression makes it easy | |
| Matches double-byte characters (including Han characters) | [^\x00-\xff] |
| Comment: can calculate string length (a double-byte character counts as 2, an ASCII character as 1) | |
| Regex matching blank lines | \n\s*\r |
| Comment: can be used to delete blank lines | |
| Regex for matching HTML tags | <(\S*?)[^>]*>.*?</\1>|<.*?/> |
| Comment: the versions circulating online are too poor; this one only matches part, and is still powerless against complex nested tags | |
| Regex to match leading and trailing whitespace | ^\s*|\s*$ |
| Comment: can delete whitespace at the start and end of a line (spaces, tabs, form feeds, etc.); a very useful expression | |
| Regular expression that matches Email addresses | \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* |
| Comment: very useful for form validation | |
| Regex for matching URLs | [a-zA-z]+://[^\s]* |
| Note: the version circulating online has very limited features; the one above basically meets the need | |
| Check whether an account name is valid (starts with a letter, 5-16 bytes, letters, digits and underscores allowed) | ^[a-zA-Z][a-zA-Z0-9_]{4,15}$ |
| Comment: very useful for form validation | |
| Match domestic phone numbers | \d{3}-\d{8}|\d{4}-\d{7} |
| Comment: matches formats like 0511-4405222 or 021-87888822 | |
| Match Tencent QQ numbers | [1-9][0-9]{4,} |
| Note: Tencent QQ numbers start at 10000 | |
| Matches mainland China postal codes | [1-9]\d{5}(?!\d) |
| Note: Mainland China postal codes are 6 digits | |
| Match ID card | \d{15}|\d{18} |
| Comment: ID card numbers in mainland China are 15 or 18 digits | |
| Match ip address | \d+\.\d+\.\d+\.\d+ |
| Comment: useful for extracting IP addresses | |
| Match specific digits: | |
| ^[1-9]\d*$ | // match positive integers |
| ^-[1-9]\d*$ | // match negative integers |
| ^-?[1-9]\d*$ | // match integers |
| ^[1-9]\d*|0$ | //Matches a non-negative integer (positive integer + 0) |
| ^-[1-9]\d*|0$ | // Match non-positive integers (negative integers + 0) |
| ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ | // Match positive floating-point numbers |
| ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ | // Match negative floating-point numbers |
| ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ | // match floating-point numbers |
| ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ | //Match non-negative floats (positive floats +0) |
| ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ | //Match non-positive floats (negative floats +0) |
| Comment: useful when processing large amounts of data; adjust as needed for specific uses | |
| Match a specific string | |
| ^[A-Za-z]+$ | //Matches a string made up of the 26 English letters |
| ^[A-Z]+$ | //Match a string composed of the 26 uppercase English letters |
| ^[a-z]+$ | //Match a string composed of the 26 lowercase English letters |
| ^[A-Za-z0-9]+$ | //Match a string composed of digits and the 26 English letters |
| ^\w+$ | //Match a string composed of digits, the 26 English letters or underscores |
| Character | Description |
|---|---|
| \ | Marks the next character as a special character, a literal character, a backreference or an octal escape. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" while "\(" matches "(". |
| ^ | 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". |
| $ | 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". |
| * | Matches the preceding subexpression zero or more times. For example, zo* matches "z" and "zoo". * is equivalent to{0,}。 |
| + | Matches the preceding subexpression one or more times. For example, "zo+" matches "zo" and "zoo" but not "z". + is equivalent to{1,}。 |
| ? | Matches the preceding subexpression zero or one time. For example, "do(es)?" matches the "do" in "do" or "does". ? is equivalent to{0,1}。 |
| {n} | n is a non-negative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob", but does match both o's in "food". |
| {n,} | n is a non-negative integer. Matches at least n times. For example, "o{2,}" does not match the "o" in "Bob", but matches all the o's in "foooood". "o{1,}" equivalent to "o+". "o{0,}"is equivalent to "o*". |
| {n,m} | m and n are non-negative integers with n<=m. Matches at least n times and at most m times. For example, "o{1,3}" will match the first three o's in "fooooood". "o{0,1}" is equivalent to "o?". Note that no space is allowed between the comma and the two numbers. |
| ? | When this character immediately follows any other quantifier (*, +, ?,{n},{n,},{n,m}) makes the pattern non-greedy. Non-greedy mode matches as few characters of the searched string as possible, while the default greedy mode matches as many as possible. For example, for the string "oooo", "o+?" matches a single "o", while "o+" matches all the "o"s. |
| . | Matches any single character except "\n". To match any character including "\n", use a pattern like "[.\n]". |
| (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 capturing the match, that is, this is a non-capturing match and does not store the result for later use. This is useful when combining the parts of a pattern with the alternation character (|). For example, industr(?:y|ies) is a more concise expression than industry|industries. |
| (?=pattern) | Positive lookahead: at any string start that matches the pattern, match and search for the search string. This is a non-capturing match, that is, the match does not need to be captured for later use. For example, "Windows(?=95|98|NT|2000)" matches "Windows" in "Windows2000" but not "Windows" in "Windows3.1". Lookahead does not consume characters: after a match occurs, the search for the next match starts immediately after the last match, not after the character containing the lookahead. |
| (?!pattern) | Negative lookahead: at any string start that does not match the pattern, match and search for the search string. This is a non-capturing match, that is, the match does not need to be captured for later use. For example, "Windows(?!95|98|NT|2000)" matches "Windows" in "Windows3.1" but not "Windows" in "Windows2000". Lookahead does not consume characters: after a match occurs, the search for the next match starts immediately after the last match, not after the character containing the lookahead. |
| x|y | Matches x or y. For example, "z|food" matches "z" or "food"; "(z|f)ood" matches "zood" or "food". |
| [xyz] | Character set. Matches any one of the included characters. For example, "[abc]" matches "a" in "plain". |
| [^xyz] | Negative character set. Matches any character not included. For example, "[^abc]" matches "p" in "plain". |
| [a-z] | Character range. Matches any character in the specified range. For example, "[a-z]" matches any lowercase letter in the range from "a" to "z". |
| [^a-z] | Negative character range. Matches any character not in the specified range. For example, "[^a-z]" matches any character not in the range from "a" to "z". |
| \b | Matches a word boundary, that is, the position between a word and a space. For example, "er\b" can match the "er" in "never" but not the "er" in "verb". |
| \B | Matches a non-word boundary. "er\B" matches "er" in "verb" but not in "never". |
| \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" character. |
| \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 | Matches any non-word character. Equivalent to "[^A-Za-z0-9_]". |
| \xn | Matches n, where n is a hexadecimal escape value. The hexadecimal escape value must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x04&1". Regular expressions can use ASCII encoding. |
| \num | Matches num, where num is a positive integer, as a reference to the matched group. For example, "(.)\1" matches two consecutive identical characters. |
| \n | Identifies an octal escape value or a backreference. If at least n previously captured subexpressions exist, n is a backreference. Otherwise, if n is an octal digit (0-7), n is an octal escape value. |
| \nm | Identifies an octal escape value or a backreference. If at least nm capturing subexpressions precede \nm, then \nm is a backreference. If at least n captures precede \nm, then \nm is a backreference followed by the literal character m. If neither condition is met and both n and m are octal digits (0-7), \nm matches the octal escape value nm. |
| \nml | If n is an octal digit (0-3) and m and l are octal digits (0-7), matches the octal escape value nml. |
| \un | Matches n, where n is a Unicode character represented by four hexadecimal digits. For example, \u00A9 matches the copyright symbol (?). |
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.