Online Common Regular Expressions

Description Regular Expression
URL [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?)
Email Address \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
QQ Number [1-9]\d{4,}
HTML Tags (with content or self-closing) <(.*)(.*)>.*<\/\1>|<(.*) \/>
Password (composed of numbers/uppercase letters/lowercase letters/punctuation marks, all four types must be present, at least 8 characters long) (?=^.{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 format) ((1|0?)[0-9]|2[0-3]):([0-5][0-9])
Chinese Characters [\u4e00-\u9fa5]
Chinese Characters and Full-Width Punctuation [\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee]
Chinese Mainland Fixed Telephone Number (\d{4}-|\d{3}-)?(\d{8}|\d{7})
Chinese Mainland Mobile Phone Number 1\d{10}
Chinese Mainland Postal Code [1-9]\d{5}
Chinese Mainland 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+)?
Word without '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})$/
Email Address /^([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+\/>)$/
Chinese Characters in Unicode Range /^[u4e00-u9fa5],{0,}$/
Matching Chinese Characters (Characters) [\u4e00-\u9fa5]
Note: Matching Chinese characters can be quite challenging; this expression makes it easier.
Matching Double-byte Characters (Including Chinese Characters) [^\x00-\xff]
Note: Useful for calculating string lengths (one double-byte character counts as 2, ASCII characters count as 1).
Matching Blank Lines \n\s*\r
Note: Useful for removing blank lines.
Matching HTML Tags <(\S*?)[^>]*>.*?</\1>|<.*?/>
Note: Many online versions are subpar; this one can handle basic cases but may struggle with complex nested tags.
Matching Leading and Trailing Whitespace Characters ^\s*|\s*$
Note: Useful for removing leading and trailing whitespace characters (including spaces, tabs, line breaks, etc.), very handy expression.
Matching Email Addresses \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Note: Very practical for form validation.
Matching URLs [a-zA-z]+://[^\s]*
Note: Many online versions are limited; this one can meet most requirements.
Matching Legal Account Names (Starts with letters, allows 5-16 bytes, allows letters, numbers, underscores) ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Note: Very practical for form validation.
Matching Chinese Landline Numbers \d{3}-\d{8}|\d{4}-\d{7}
Note: Matches formats like 0511-4405222 or 021-87888822.
Matching Tencent QQ Numbers [1-9][0-9]{4,}
Note: Tencent QQ numbers start from 10000.
Matching Chinese Mainland Postal Codes [1-9]\d{5}(?!\d)
Note: Chinese mainland postal codes are 6-digit numbers.
Matching ID Numbers \d{15}|\d{18}
Note: Chinese mainland ID numbers can be 15 or 18 digits.
Matching IP Addresses \d+\.\d+\.\d+\.\d+
Note: Useful for extracting IP addresses.
Matching Specific Numbers:
^[1-9]\d*$ //Matches positive integers
^-[1-9]\d*$ //Matches negative integers
^-?[1-9]\d*$ //Matches integers
^[1-9]\d*|0$ //Matches non-negative integers (positive integers + 0)
^-[1-9]\d*|0$ //Matches non-positive integers (negative integers + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //Matches positive floating-point numbers
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //Matches negative floating-point numbers
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //Matches floating-point numbers
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //Matches non-negative floating-point numbers (positive floating-point numbers + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //Matches non-positive floating-point numbers (negative floating-point numbers + 0)
Note: Useful for handling large amounts of data, but modifications may be necessary for specific applications.
Matching Specific Strings:
^[A-Za-z]+$ //Matches strings consisting of 26 English letters
^[A-Z]+$ //Matches strings consisting of 26 uppercase English letters
^[a-z]+$ //Matches strings consisting of 26 lowercase English letters
^[A-Za-z0-9]+$ //Matches strings consisting of numbers and 26 English letters
^\w+$ //Matches strings consisting of numbers, 26 English letters, or underscores
Character Description
\ Specifies the next character as either a special character, a literal character, a back reference, or an octal escape. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(\" matches "(".
^ Matches the beginning of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position following "\n" or "\r".
$ Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches the position preceding "\n" or "\r".
* 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+" matches "zo" as well as "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "do(es)?" can match "do" or "does" in "do". ? is equivalent to {0,1}.
{n} n is a non-negative integer. Matches exactly n times. For example, "o{2}" does not match "o" in "Bob" but matches both o's in "food".
{n,} n is a non-negative integer. Matches at least n times. For example, "o{2,}" does not match "o" in "Bob" but matches all o's in "foooood". "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".
{n,m} m and n are non-negative integers, where n<=m. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood". "o{0,1}" is equivalent to "o?". Note that there should be no space between the comma and the two numbers.
? When following any other quantifier (*, +, ?, {n}, {n,}, {n,m}), matches patterns in a non-greedy way. Non-greedy matches try to match as few characters as possible, while the default greedy matches try to match as many characters as possible. For example, for the string "oooo", "o+?" matches a single "o", while "o+" matches all "o".
. Matches any single character except "\n". To match any character including "\n", use a pattern like "[.\n]".
(pattern) Matches pattern and captures the match. The matched portion can be retrieved from the Matches collection in VBScript, SubMatches collection in JScript, or $0…$9 properties. To match parentheses characters, use "\(\" or "\)\".
(?:pattern) Matches pattern but does not capture the match, making it a non-capturing match that is not stored for later use. This is useful when combining parts of a pattern using the | character. For example, "industr(?:y|ies)" is a more concise expression than "industry|industries".
(?=pattern) Positive lookahead. Matches at any position where pattern begins. This is a non-capturing match, meaning it does not need to be captured for later use. For example, "Windows(?=95|98|NT|2000)" can match "Windows" in "Windows2000" but not in "Windows3.1". Lookaheads do not consume characters, so after a match occurs, the next match search begins immediately after the last match, rather than starting from the character after the lookahead.
(?!pattern) Negative lookahead. Matches at any position where pattern does not begin. This is a non-capturing match, meaning it does not need to be captured for later use. For example, "Windows(?!95|98|NT|2000)" can match "Windows" in "Windows3.1" but not in "Windows2000". Like lookaheads, negative lookaheads do not consume characters.
x|y Matches either x or y. For example, "z|food" can match "z" or "food". "(z|f)ood" can match "zood" or "food".
[xyz] Character set. Matches any one of the enclosed characters. For example, "[abc]" can match "a" in "plain".
[^xyz] Negative character set. Matches any character not enclosed. For example, "[^abc]" can match "p" in "plain".
[a-z] Character range. Matches any character within the specified range. For example, "[a-z]" can match any lowercase letter from "a" to "z".
[^a-z] Negative character range. Matches any character not within the specified range. For example, "[^a-z]" can match any character not between "a" and "z".
\b Matches a word boundary, indicating the position between a word and a space. For example, "er\b" can match "er" in "never" but not in "verb".
\B Matches a non-word boundary. "er\B" can match "er" in "verb" but not in "never".
\cx Matches a control character specified by x. For example, \cM matches a Control-M or carriage return. x must be one of A-Z or a-z. Otherwise, c is treated as a literal "c" character.
\d Matches a digit character. Equivalent to [0-9].
\D Matches a non-digit 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 space, tab, form feed, 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 character. Equivalent to \x09 and \cI.
\v Matches a vertical tab character. Equivalent to \x0b and \cK.
\w Matches any word character, including 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 represented by four hexadecimal digits. For example, \x41 matches "A". \x041 is equivalent to \x04&1. ASCII encoding can be used in regular expressions.
\num Matches num, where num is a positive integer. Refers to the match obtained from num. For example, "(.)\1" matches two consecutive identical characters.
\n Identifies an octal escape value or a back reference. If there are at least n captured subexpressions before \n, then n is a back reference. Otherwise, if n is an octal digit (0-7), then n is an octal escape value.
\nm Identifies an octal escape value or a back reference. If there are at least nm captured, then nm is a back reference. If there are at least n captures, then n is a back reference followed by the literal character m. If neither of these conditions is met and both n and m are octal digits (0-7), then \nm matches the octal escape value nm.
\nml If n is an octal digit (0-3) and both 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 (©).
Visit History:

Links: google