99+ commonly used regular expressions, enough for free!
Regular describes a string matching pattern, but for many people writing regular is "Landry's torture". If you don't need to use it frequently, you won't even think about learning it. This article will sort out and share with you some commonly used regular expressions. Do you want to use regular expressions for free? Come and collect it!
You want to have sex for free, right? This article will give you enough at one time! Rush 99 first! (If you still think it’s not enough, just leave a comment and add more. This article will continue to be updated and added!!)
Another little tip, students who have difficulty reading can use this websitejex.im/ regulex/, visualize regular rules and fall in love with reading regular rules!
For example: regular rules for verifying email addresses: ^\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-.] \w )*$
After visualization, just look at the pictures and talk, novices can do it, it’s really tql! !
Okay, let’s rush!
Number related
Mobile phone number (starting with 1):
/^(?:(?:\ |00)86 )?1\d{10}$/
Mobile phone number (starting with 13 to 19):
/^(?:(?:\ |00) 86)?1[3-9]\d{9}$/
Mobile phone number (starting with the mobile phone number range announced by the Ministry of Industry and Information Technology):
/^( ?:(?:\ |00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])| (?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/
Domestic landline number:
/\d{3}-\d{8}|\d{4}-\d{7}/
Email number:
/^\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-. ]\w )*$/
Postal code:
/[1-9]\d{5}(?!\d)/
ID number:
/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1 -9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/
Bank card number (public and private account):
/^[1-9]\d{9,29}$/
License number:
/^[Beijing, Tianjin, Shanghai, Chongqing, Hebei, Yunnan, Liaoning, Hunan, Anhui, Shandong, New Jiangsu, Zhejiang, Jiangxi, Hubei, Guangxi, Gansu, Shanxi, Mongolia, Shaanxi, Jilin, Fujian, Guangdong, Qinghai, Tibet, Sichuan, Ningqiong, Ambassador][A-HJ-NP-Z][A -HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9 HONG KONG and MACAO]$/
- ##QQ number:
/^[1-9][0-9]{4,10}$/
- WeChat ID:
/^[a-zA-Z ][-_a-zA-Z0-9]{5,19}$/
- Version number (x.y.z):
/^\d (?:\ .\d ){2}$/
##Legal account number 1 (starting with a letter, 5-16 digits, alphanumeric and underscore allowed): - /^[a- zA-Z][a-zA-Z0-9_]{4,15}$/
- /^[a-zA-Z0-9_-]{4,16}$/
- /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z] ).{8,10}$/
- `~ ()- =
* ):
##/^(?![a-zA-Z] $)(?![A-Z0-9] $ )(?![A-Z\W_!@#$%^&* ~()- =] $)(?![a-z0-9] $)(?![a-z\\W_!@#$%^ & *~()- =] $)(?![0-9\W_!@#$%^&* ~()- =] $)[a-zA-Z0-9\\W_!@#$ %^&*~()- =]/
- /^(((ht|f)tps?):\/\/)? (^!@#$%^&*?.\s-?\.) [a-z]{2,6}\/?/
-
URL with port number : /^((ht|f)tps?:\/\/)?[\w-] (\.[\w-] ) :\d{1,5}\/?$/ -
ip-v4: /\\b(?:(?: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]?)\\b/ -
ip-v6: /(([0-9a-fA-F]{1 ,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|( [0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1, 4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){ 1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}( :[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a -fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}) {1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0 ,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}( (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25 [0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1 ,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9] )\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])) /
Only numbers:
- /^[0-9]* $/
- or
/^\d{1,}$/
Integer: /^-?[0-9]\d *$/ -
Positive integer: /^\ ?[1-9]\d*$/ -
/^-[1-9]\d*|0$/##Non-positive integers:
-
/^-[ 1-9]\d*$/Negative integers:
##Non-negative integer:
/^\d $/Floating point number:
/^(-?\d )(\.\d )?$/##Positive floating point number:
/^[ 1-9]\d*\.\d*|0\.\d*[1-9]\d*$/
Negative floating point number:
/^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)/
Decimal:
/^-?\d \.\d $/
Positive/Negative/Decimal:
/^(\-|\ ) ?\d (\.\d )?$/
Positive real numbers retain 2 decimal places:
/^[0-9] (.[0- 9]{2})?$/
Positive real numbers retain 1 to 3 digits after the decimal point:
/^[0-9] (.[0-9]{1,3})?$/
n digits:
/^\d{n}$/
At least n digits:
/ ^\d{n,}$/
Numbers from m to n digits:
/^\d{m,n}$/
Contains at least one of the numbers and letters:
/^[A-Za-z0-9] $/
Must Contains numbers and letters:
/^(?=.*[a-zA-Z])(?=.*\d). $/
- ##md5 Value:
/^([a-f\d]{32}|[A-F\d]{32})$/
##base64 Value: - / ^\s*data:(?:[a-z] \/[a-z0-9- .] (?:;[a-z-] =[a-z0-9-] )?)?(?:;base64) ?,([a-z0-9!$&',()* ;=\-._~:@/?%\s]*?)\s*$/i
- Characters from m to n digits:
- /^.{3,20}$/
- /^[A-Za-z] $/
- /^[A-Z] $/
##Lowercase English alphabetic characters: /^[a-z] $/ -
Chinese characters: /^[\u4e00-\u9fa5]{0,}$/ -
Full-width symbols: /[\uFF00- \uFFFF]/ -
/[\u0000-\u00FF]/##Half-width symbols:
-
/^[\u4E00-\u9FA5A-Za-z0-9_] $/Chinese characters , at least one of English, numbers, and underscores:
-
/[^~\x22] /does not contain the character "~ ”:
-
/(.)\1 /Characters are repeated continuously:
-
⌚Time related
24-hour time (HH:mm:ss):
/^(?:[01 ]\d|2[0-3]):[0-5]\d:[0-5]\d$/-
/^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$/12 hour time (hh :mm:ss):
-
/([0-1]?[0-9]|2[0-3])([0-5] [0-9])([0-5][0-9])$/24-hour time (HHmmss):
-
/^\d{4}-\d{1,2}-\d{1,2}/Date 1 (yyyy-MM-dd, such as 2222-01-01 , the year must be 4 digits):
-
/^\d{1,4}(-)(1[0-2]|0?[1-9])\1 (0?[1-9]|[1-2]\d|30|31)$/Date 2 (such as 333-01-01, the year can be less than 4 digits):
-
/^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[ 1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12 ][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1 -9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[ 13579][26])|((0[48]|[2468][048]|[3579][26])00))0229))$/Date 3 (yyyyMMdd, such as 20220202):
-
/^\d{4}([/:-\S])(1[0-2]|0?[1-9])\1 (0?[1-9]|[1-2]\d|30|31) (?:[01]\d|2[0-3]):[0-5]\d:[0-5 ]\d$/Date time 1 (YYYYMMDD HH:mm:ss):
-
/^[1-9]\d{3}-(0[1-9]|1[ 0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s (20|21|22|23|[0-1]\d ):[0-5]\d:[0-5]\d$/Date Time 2:
-
/^(0?[1-9]|1[0-2])$/12 months a year ((01~09 or 1~12)) :
-
/^((0?[1-9])|((1|2)[0-9])|30|31)$/31 days in a month (01~09 or 1~ 31):
-
/^(0?[13578]|1[02])$/ ##A month with 30 days:
/(0[469]|11)-(0[1-9]|[12][0-9]|30)/2 months 28 days ("02-28"):
/^02-(0[1-9]|[1][0-9]|2[0-8])$/Leap year:
/^(((19|20)([13579][26]|[2468][048]|0[48]))|(2000))$/February in a leap year (such as 2008-02-01):
/^(((19|20)([13579][26]|[2468] [048]|0[48]))|(2000))-0?2-(0?[1-9]|[12]\d)$/Date (including leap year, big and small month judgment):
/((((19|20)\d{2})-(0?(1|[3-9])|1[012]) -(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)| (((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([ 13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/Year Interval-year (such as 19 to 20 years):
/^((19|20)\d{2})$/##Year interval-year Month (such as 1999-01):
/^((((19|20)\d{2})-(0?[13-9]|1[012]))|(((19|20 )\d{2})-(0?[13578]|1[02]))|(((19|20)\d{2})-0?2)|((((19|20)( [13579][26]|[2468][048]|0[48]))|(2000))-0?2))$/
-
Year range -Year, month and day (such as 1999-01-01):
/^((((19|20)\d{2})-(0?[13-9]|1[012])-(0 ?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|((( 19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((19|20)([13579][ 26]|[2468][048]|0[48]))|(2000))-0?2-29))$/.test('2021-02-21')$/
Year interval - year, month and day (the interval symbol can be - / or empty):
/^(?:(?:1[6-9]|[2-9][ 0-9])[0-9]{2}([-/.]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[ 1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(? :0?[13578]|1[02])\1(?:31))|(?:(?:1[6-9]|[2-9][0-9])(?:0[ 48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)([-/.]?)0?2 \2(?:29))$/
Programming related
Hexadecimal color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
Extract web page color code:
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
Video link address:
/^https?:\/\/(. \/) . (\.(swf|avi|flv|mpg|rm|mov|wav|asf |3gp|mkv|rmvb|mp4))$/i
Picture link address:
/^https?:\/\/(. \/) . (\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i
- ##mac Address:
/^( (([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/ i
- Subnet mask:
/^((?:(?:25[0-5]|2[0-4]\\d| [01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d ))$/
- File extension validation:
/^([a-zA-Z]\\:|\\\\)\\\\ ([^\\\\] \\\\)*[^\\/:*?"|] \\.txt(l)?$/
- java package name (x.x.x):
/^([a-zA-Z_]\w*) ([.][a-zA-Z_]\w*) $/
- xml file:
/^([a-zA-Z] -?) [a-zA-Z0-9] \\.[x|X][m|M ][l|L]$/
- html Comment:
//g
- html Tag 1:
/]*>(.*?)?/
- html Tag 2:
/]*>.*?\1>|/
## Leading and trailing blank characters: - /^\s*|\s*$/
- /^\\s*[a-zA-Z\\-] \\s*[:]{1}\\s[a-zA-Z0-9\ \s.#] [;]{1}/
- /(]*)(href="https?:\\/\\/)((?!(?:(?:www\\.)?'.implode('|(?: www\\.)?', $follow_list).'))[^" rel="external nofollow" ] )"((?!.*\\brel=)[^>]*)(?:[^ >]*)>/
- /\\]*[ src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*)/
- /^thunder:\/\/[a-zA-Z0-9] =$/
- /^ed2k :\/\/|file|. |\/$/
- /^\/(\w \/) \w \.\w $/
- /^[a-zA-Z]:\\(?:\w \\ )*\w \.\w $/
- amount (loose, optional is negative, the first bit can be 0, supports thousandth separation):
- /^-?\d (,\d{3})*(\.\d{1,2})?$/
- /(^[1-9]{1}[0-9]*$)|(^[0- 9]*\.[0-9]{2}$)/
- /(^[1-9]([0-9] )?(\.[0-9]{1,2})?$)|(^(0){1}$)|( ^[0-9]\.[0-9]([0-9])?$)/
- /(^[EeKkGgDdSsPpHh] \d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa]) |(1[45]))\d{7}$)/
- /^[a-zA-Z]\d{ 6}\([\dA]\)$/
- /^[1|5|7]\d{6}\( \d\)$/
- /^[a-zA-Z][0-9]{9}$/
- /^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3} |300[\d]{3}|600[\d]{3}|60[\d]{4})$/
##Words that do not contain abc : /\b((?!abc)\w) \b/ -
100. To be continued... - ##Summary:
This article briefly organizes a wave of regular rules, many of which are also learned while reading, with the help of jex .im/regulex/, awesome!
If you have anything to add, please leave a comment, or if you find any errors, please point them out and they will be corrected immediately. I hope it can be helpful to your regular learning and use~
Original address: https://juejin.cn/post/7119242343798013959More programming related For knowledge, please visit:programming teaching
! !

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP regular expression verification: Number format detection When writing PHP programs, it is often necessary to verify the data entered by the user. One of the common verifications is to check whether the data conforms to the specified number format. In PHP, you can use regular expressions to achieve this kind of validation. This article will introduce how to use PHP regular expressions to verify number formats and provide specific code examples. First, let’s look at common number format validation requirements: Integers: only contain numbers 0-9, can start with a plus or minus sign, and do not contain decimal points. floating point

As a modern programming language, Go language provides powerful regular expressions and string processing functions, allowing developers to process string data more efficiently. It is very important for developers to master regular expressions and string processing in Go language. This article will introduce in detail the basic concepts and usage of regular expressions in Go language, and how to use Go language to process strings. 1. Regular expressions Regular expressions are a tool used to describe string patterns. They can easily implement operations such as string matching, search, and replacement.

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

To validate email addresses in Golang using regular expressions, follow these steps: Use regexp.MustCompile to create a regular expression pattern that matches valid email address formats. Use the MatchString function to check whether a string matches a pattern. This pattern covers most valid email address formats, including: Local usernames can contain letters, numbers, and special characters: !.#$%&'*+/=?^_{|}~-`Domain names must contain at least One letter, followed by letters, numbers, or hyphens. The top-level domain (TLD) cannot be longer than 63 characters.

The method of using regular expressions to verify passwords in Go is as follows: Define a regular expression pattern that meets the minimum password requirements: at least 8 characters, including lowercase letters, uppercase letters, numbers, and special characters. Compile regular expression patterns using the MustCompile function from the regexp package. Use the MatchString method to test whether the input string matches a regular expression pattern.

PHP is a widely used programming language, especially popular in the field of web development. In the process of web development, we often encounter the need to filter and verify text input by users, among which character filtering is a very important operation. This article will introduce how to use regular expressions in PHP to implement Chinese character filtering, and give specific code examples. First of all, we need to clarify that the Unicode range of Chinese characters is from u4e00 to u9fa5, that is, all Chinese characters are in this range.

PHP Regular Expressions: Exact Matching and Exclusion Fuzzy inclusion regular expressions are a powerful text matching tool that can help programmers perform efficient search, replacement and filtering when processing text. In PHP, regular expressions are also widely used in string processing and data matching. This article will focus on how to perform exact matching and exclude fuzzy inclusion operations in PHP, and will illustrate it with specific code examples. Exact match Exact match means matching only strings that meet the exact condition, not any variations or extra words.

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then