{if $Think.config.en.regexdso.status == '1'} {/if

Common Regular Expressions

Description Regular Expression
Website 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, all four must be present, more than 8 characters) (?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$
Date (YYYY-MM-DD) (\d{4}|\d{2})-((1[0-2])|(0?[1-9]))-(([12][0-9])|(3[01])|(0?[1-9]))
Date (MM/DD/YY) ((1[0-2])|(0?[1-9]))/(([12][0-9])|(3[01])|(0?[1-9]))/(\d{4}|\d{2})
Time (HH:MM, 24-hour format) ((1|0?)[0-9]|2[0-3]):([0-5][0-9])
Chinese Characters [\u4e00-\u9fa5]
Chinese and Full-width Punctuation [\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee]
Fixed Phone Numbers in Mainland China (\d{4}-|\d{3}-)?(\d{8}|\d{7})
Mobile Numbers in Mainland China 1\d{10}
Postal Codes in Mainland China [1-9]\d{5}
ID Numbers in Mainland China (15 or 18 digits) \d{15}(\d\d[0-9xX])?
Non-negative Integers (positive integers or zero) \d+
Positive Integers [0-9]*[1-9][0-9]*
Negative Integers -[0-9]*[1-9][0-9]*
Integers -?\d+
Decimals (-?\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})$/
Email /^([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 Tag /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
Chinese Character Range in Unicode /^[u4e00-u9fa5],{0,}$/
Regex for matching Chinese characters [\u4e00-\u9fa5]
Note: Matching Chinese characters can be quite a headache; this expression simplifies it.
Matching double-byte characters (including Chinese) [^\x00-\xff]
Note: This can be used to calculate the length of a string (counting each double-byte character as 2, and ASCII characters as 1).
Regex for matching blank lines \n\s*\r
Note: This can be used to remove blank lines.
Regex for matching HTML tags <(\S*?)[^>]*>.*?</\1>|<.*?/>
Note: The versions found online are too poor; this one can only match parts and is still ineffective against complex nested tags.
Regex for matching leading and trailing whitespace characters ^\s*|\s*$
Note: This can be used to remove whitespace characters at the start and end of a line (including spaces, tabs, page breaks, etc.); it is a very useful expression.
Regex for matching email addresses \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Note: Very practical for form validation.
Regex for matching website URLs [a-zA-z]+://[^\s]*
Note: The versions found online have limited functionality; this one can basically meet the needs.
Regex for validating account legality (starting with a letter, allowing 5-16 bytes, allowing letters, numbers, and underscores) ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Note: Very practical for form validation.
Regex for matching domestic phone numbers \d{3}-\d{8}|\d{4}-\d{7}
Note: Matches formats like 0511-4405222 or 021-87888822.
Regex for matching QQ numbers [1-9][0-9]{4,}
Note: QQ numbers start from 10000.
Regex for matching postal codes in mainland China [1-9]\d{5}(?!\d)
Note: Postal codes in mainland China are 6-digit numbers.
Regex for matching ID cards \d{15}|\d{18}
Note: ID cards in mainland China are either 15 or 18 digits.
Regex for matching IP addresses \d+\.\d+\.\d+\.\d+
Note: Useful for extracting IP addresses.
Matching specific digits:
^[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 when processing large amounts of data; be sure to adjust as needed in specific applications.
Matching specific strings
^[A-Za-z]+$ // Matches strings composed of the 26 English letters
^[A-Z]+$ // Matches strings composed of uppercase English letters
^[a-z]+$ // Matches strings composed of lowercase English letters
^[A-Za-z0-9]+$ // Matches strings composed of numbers and the 26 English letters
^\w+$ // Matches strings composed of digits, the 26 English letters, or underscores
Character Description
\ Marks the next character as 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 position 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 position 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 sub-expression zero or more times. For example, zo* can match "z" and "zoo". * is equivalent to {0,}.
+ Matches the preceding sub-expression one or more times. For example, "zo+" can match "zo" and "zoo", but cannot match "z". + is equivalent to {1,}.
? Matches the preceding sub-expression zero or one time. For example, "do(es)?" can match "do" or "does". ? is equivalent to {0,1}.
{n} n is a non-negative integer. Matches exactly n times. For example, "o{2}" cannot match the "o" in "Bob", but can match the two o's in "food".
{n,} n is a non-negative integer. Matches at least n times. For example, "o{2,}" cannot match the "o" in "Bob", but can match all o's in "foooood". "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".
{n,m} m and n are both non-negative integers, where 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 there cannot be spaces between the comma and the two numbers.
? When this character follows any other quantifier (*, +, ?, {n}, {n,}, {n,m}), the matching mode is non-greedy. The 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 the string "oooo", "o+?" will match a single "o", while "o+" will match all "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 obtained from the resulting Matches collection, accessed through the SubMatches collection in VBScript or the $0…$9 properties in JScript. To match parentheses characters, use "\( or "\)".
(?:pattern) Matches pattern but does not capture the match, meaning it is a non-capturing match and is not stored for later use. This is useful when combining parts of a pattern using the or character "("|". For example, "industr(?:y|ies)" is a more concise expression than "industry|industries".
(?=pattern) Positive lookahead, matches if the string starts with that matches pattern. 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 cannot match "Windows" in "Windows3.1". Lookaheads do not consume characters, which means that after a match occurs, the next search for a match starts immediately after the last match, not from the character that includes the lookahead.
(?!pattern) Negative lookahead, matches if the string does not start with that matches pattern. 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 cannot match "Windows" in "Windows2000". Lookaheads do not consume characters, which means that after a match occurs, the next search for a match starts immediately after the last match, not from the character that includes the lookahead.
x|y Matches x or y. For example, "z|food" can match “z” or “food”. "(z|f)ood" matches “zood” or "food".
[xyz] Character set. Matches any one of the contained characters. For example, "[abc]" can match the "a" in "plain".
[^xyz] Negative character set. Matches any character not contained. For example, "[^abc]" can match the "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 in the specified range. For example, "[^a-z]" can match any character not in the "a" to "z" range.
\b Matches a word boundary, referring to the position between a word and a space. For example, "er\b" can match "er" in "never", but cannot match "er" in "verb".
\B Matches a non-word boundary. "er\B" can match "er" in "verb", but cannot match "er" in "never".
\cx Matches a control character indicated by x. For example, \cM matches a Control-M or carriage return character. 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 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 underscores. 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. Hexadecimal escape values must be exactly two digits long. 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 that refers to a captured match. For example, "(.)\1" matches two consecutive identical characters.
\n Indicates an octal escape value or a back-reference. If there have been at least n captured sub-expressions 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 Indicates an octal escape value or a back-reference. If there have been at least nm captured sub-expressions before \nm, then nm is a back-reference. If there have been at least n captures before \nm, then n is a back-reference followed by literal m. If neither of the previous conditions are met, if n and m are both octal digits (0-7), then \nm matches the octal escape value nm.
\nml If n is an octal digit (0-3) and m and l are both octal digits (0-7), then 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 (©).

Complete List of Common Regular Expressions - Including URLs, mobile numbers, alphanumeric characters, form validation, etc.

Welcome to use our list of common regular expressions! Here you can find various practical regular expressions covering URL validation, mobile number validation, alphanumeric validation, and common form validation scenarios. Whether you are performing data validation, string handling, or search and replace, you will find corresponding regular expression examples here.

Common Regular Expression Examples

  • URL regular expression: Used to validate if the URL format is correct, such as: http://www.example.com.
  • Mobile number regular expression: Validates mobile number formats, supporting different country number rules.
  • Alphanumeric regular expression: Matches a combination of letters and numbers, used for username or password validation.
  • Form validation regular expression: Used for validating form input, such as email, ID numbers, postal codes, etc.
  • String handling regular expression: Includes common handling methods such as removing spaces and replacing special characters.
  • Regular expression replacement: Replaces strings using regular expressions, supporting complex pattern matching.
  • Regular expression search: Used to find matches in strings, supporting various matching modes.

Common Regular Expression Instances

The following are some common regular expressions and their descriptions to help developers quickly get started:

  • Email address validation:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
  • Mobile number validation:/^(1[3-9])\d{9}$/
  • Website validation:/^(http:\/\/|https:\/\/)?[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/
  • Validation for only numbers and letters:/^[A-Za-z0-9]+$/
  • ID number validation:/^\d{15}|\d{18}$/

How to Use Regular Expressions for Validation and Processing

Regular expressions are widely used for data validation and string processing, for instance:

  • Form validation: Use regular expressions to validate the format of user input data, such as email, phone numbers, etc., ensuring the data is legal.
  • Data cleaning: Regular expressions can be used to extract or replace specific strings from text, such as removing extra spaces or replacing special characters.
  • Information matching: Quickly find matches in a string using regular expressions, allowing fast retrieval in large datasets.

Start Using Regular Expressions

With our comprehensive regular expression guide, you can easily find the necessary regular expressions and apply them to your projects. Whether it is validating data, processing strings, or performing complex pattern matching, our regular expression library can meet your needs.

We hope this tool can assist you in your development work. If you have more needs for regular expressions, feel free to check out our other related tools and resources.

Your footpath:
Choose Language