/
/
Replace text:
replace

Commonly used regular expressions

I. Expression for verifying numbers

useRegular expressionsExampleillustrate
number^\d+$12345Only non-negative integers (0 or positive integers) are allowed.
n-digit number^\d{n}$1234 (n=4)Exactly n digits
At least n digits^\d{n,}$12345 (n=3)At least n digits
mn digits^\d{m,n}$1234 (m=2,n=4)m to n digits
Zero and non-zero starting numbers^(0|[1-9]\d*)$0, 1230 or an integer starting with a non-zero value.
Non-zero numbers can have a maximum of two decimal places.^[1-9]\d*(\.\d{1,2})?$12.34Positive integers or numbers with 1-2 decimal places
Positive and negative numbers with 1-2 decimal places^-?\d+(\.\d{1,2})?$-12.34, 56.7Positive and negative numbers, 1-2 decimal places
Positive numbers, negative numbers, decimals^[-+]?\d+(\.\d+)?$+12.3, -0.5Positive and negative integers or decimals
Two-decimal-positive real numbers^\d+(\.\d{2})?$12, 12.34Positive integers or two decimal places
Positive real numbers with 1 to 3 decimal places^\d+(\.\d{1,3})?$12.3, 12.345Positive integer or 1-3 decimal places
Non-zero positive integers^[1-9]\d*$123Positive integers that do not contain 0
Non-zero negative integers^-[1-9]\d*$-123Negative integers that do not contain 0
non-negative integers^\d+$0, 1230 or a positive integer
non-positive integers^(-\d+|0)$-123, 00 or negative integer
nonnegative floating-point numbers^\d+(\.\d+)?$0, 12.30 or positive floating-point number
Non-positive floating point numbers^(-\d+(\.\d+)?|0+(\.0+)?)$-12.3, 0, 0.00 or negative floating-point number
Positive floating point^(([1-9]\d*)|0)\.\d+$0.1, 12.3Floating-point numbers greater than 0
Negative score^-(([1-9]\d*)|0)\.\d+$-0.1, -12.3Floating-point numbers less than 0
floating-point numbers^-?\d+(\.\d+)?$-12.3, 0, 45.6Positive and negative floating-point numbers

Expressions for validating characters

useRegular expressionsExampleillustrate
English and numbers^[A-Za-z0-9]+$abc123Only English letters and numbers are allowed.
4-40 characters of English letters and numbers^[A-Za-z0-9]{4.40}$abc123454-40 characters of English letters and numbers
All characters of length 3-20^.{3,20}$abc, 12345678901234567890Any character, 3-20 positions
26 letters of the English alphabet^[A-Z-z]+$abcXYZOnly uppercase and lowercase English letters are allowed
26 capital letters of the English alphabet^[A-Z]+$ABCXYZOnly uppercase English letters are allowed
26 lowercase English letters^[a-z]+$abcxyzLowercase English letters are allowed
Numbers and the 26 letters of the English alphabet^[A-Za-z0-9]+$abc123Only numbers and English letters are allowed
Numbers, letters, or underscores^\w+$abc_123Numbers, letters, or underscores
3-20 digits, letters, or underscores^\w{3,20}$abc_1233-20 digits, letters, or underscores
English letters, numbers, and underscores^[A-Za-z0-9_]+$abc_123English letters, numbers, and underscores are allowed.
English letters and numbers (excluding underscores)^[A-Za-z0-9]+$abc123English letters and numbers are allowed, excluding underscores.
You can enter content other than characters such as %&',;=?$".^[^%&',;=?$\x22]+$abc123!@#Excluding characters such as %&',;=?$".
Do not enter characters containing ~^[^~]+$abc123Excluding the ~ character

III. Special Requirements Expressions

useRegular expressionsExampleillustrate
Email address^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$test@mail.comCommon email formats
domain name[a-zA-Z0-9][-a-zA-Z0-9]{0.62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0.62})+\.?www.example.comSupports multi-level domains
Internet URL^[a-zA-Z]+://[^\s]+$https://abc.comCommon URL formats
legitimate account^[a-zA-Z][a-zA-Z0-9_]{4,15}$abc_123Beginning with a letter, 5-16 characters
Password (starts with a letter, 6-18 characters)^[a-zA-Z]\w{5,17}$a12345_Beginning with a letter, 6-18 characters
Strong password (no special characters)^(?=.*\d)(?=.*[az])(?=.*[AZ])[a-zA-Z0-9]{8,10}$Abc123458-10 characters, including uppercase and lowercase letters and numbers.
Strong password (may contain special characters)^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$Abc12345!8-10 characters, including uppercase and lowercase letters, numbers, and special characters.
Date format^\d{4}-\d{1,2}-\d{1,2}$2023-01-01yyyy-mm-dd
12 months a year^(0?[1-9]|1[0-2])$01, 1201-12 or 1-12
31 days in a month^((0?[1-9])|((1|2)[0-9])|30|31)$01, 3101-31 or 1-31
Input money (integer)^(0|[1-9][0-9]*)$10000non-negative integers
Input of money (negative numbers allowed)^(0|-?[1-9][0-9]*)$-10000Negative numbers are allowed
Money input (decimal)^[0-9]+(\.[0-9]{1,2})?$10000.00Maximum two decimal places
Money input (with thousands separator)^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?$10,000.00Thousandths support
XML file^([a-zA-Z]+-?)+[a-zA-Z0-9]+\.[xX][mM][lL]$test-1.xmlXML filename
Double-byte characters[^\x00-\xff]Chinese characters, JapaneseNon-ASCII characters
blank line^\s*$(blank line)Match blank lines
HTML tags<[^>]+><div>Simple HTML tags
Leading and trailing whitespace characters^\s*|\s*$abcRemove leading and trailing whitespace
IPv4 address((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}192.168.1.1IPv4 format