Table of Contents
Number related
Home headlines 99+ commonly used regular expressions, enough for free!

99+ commonly used regular expressions, enough for free!

Jul 19, 2022 am 11:10 AM
regular expression

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 )*$

99+ commonly used regular expressions, enough for free!

After visualization, just look at the pictures and talk, novices can do it, it’s really tql! !

Okay, let’s rush!

  • 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}$/

  • Legal account number 2 (4-16 digits, letters, numbers, and underscores allowed) , minus sign):
  • /^[a-zA-Z0-9_-]{4,16}$/

  • Strong password 1 (must contain uppercase and lowercase letters A combination of letters and numbers, special characters cannot be used, the length is between 8-10):
  • /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z] ).{8,10}$/

  • Strong password 2 (must contain letters, numbers, special characters: **@#$%^&
  • `~ ()- =

    * ):

  • ##/^(?![a-zA-Z] $)(?![A-Z0-9] $ )(?![A-Z\W_!@#$%^&* ~()- =] $)(?![a-z0-9] $)(?![a-z\\W_!@#$%^ & *~()- =] $)(?![0-9\W_!@#$%^&* ~()- =] $)[a-zA-Z0-9\\W_!@#$ %^&*~()- =]/

URL:
    /^(((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])) /
  • Number related

Only numbers:
    /^[0-9]* $/
  • or

    /^\d{1,}$/

    Integer:
  • /^-?[0-9]\d *$/
  • Positive integer:
  • /^\ ?[1-9]\d*$/
  • ##Non-positive integers:

    /^-[1-9]\d*|0$/
  • Negative integers:

    /^-[ 1-9]\d*$/
  • ##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

Character related

    Characters from m to n digits:
  • /^.{3,20}$/

  • English alphabetic characters:
  • /^[A-Za-z] $/

  • Uppercase English alphabetic characters:
  • /^[A-Z] $/

    ##Lowercase English alphabetic characters:
  • /^[a-z] $/
  • Chinese characters:
  • /^[\u4e00-\u9fa5]{0,}$/
  • Full-width symbols:
  • /[\uFF00- \uFFFF]/
  • ##Half-width symbols:

    /[\u0000-\u00FF]/
  • Chinese characters , at least one of English, numbers, and underscores:

    /^[\u4E00-\u9FA5A-Za-z0-9_] $/
  • does not contain the character "~ ”:

    /[^~\x22] /
  • Characters are repeated continuously:

    /(.)\1 /
  • ⌚Time related

24-hour time (HH:mm:ss):

/^(?:[01 ]\d|2[0-3]):[0-5]\d:[0-5]\d$/
  • 12 hour time (hh :mm:ss):

    /^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$/
  • 24-hour time (HHmmss):

    /([0-1]?[0-9]|2[0-3])([0-5] [0-9])([0-5][0-9])$/
  • Date 1 (yyyy-MM-dd, such as 2222-01-01 , the year must be 4 digits):

    /^\d{4}-\d{1,2}-\d{1,2}/
  • Date 2 (such as 333-01-01, the year can be less than 4 digits):

    /^\d{1,4}(-)(1[0-2]|0?[1-9])\1 (0?[1-9]|[1-2]\d|30|31)$/
  • Date 3 (yyyyMMdd, such as 20220202):

    /^((([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 time 1 (YYYYMMDD HH:mm:ss):

    /^\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 2:

    /^[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$/
  • 12 months a year ((01~09 or 1~12)) :

    /^(0?[1-9]|1[0-2])$/
  • 31 days in a month (01~09 or 1~ 31):

    /^((0?[1-9])|((1|2)[0-9])|30|31)$/
  • A month with 31 days:

    /^(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*$/

  • Find CSS properties:
  • /^\\s*[a-zA-Z\\-] \\s*[:]{1}\\s[a-zA-Z0-9\ \s.#] [;]{1}/

  • Extract page hyperlink:
  • /(]*)(href="https?:\\/\\/)((?!(?:(?:www\\.)?'.implode('|(?: www\\.)?', $follow_list).'))[^" rel="external nofollow" ] )"((?!.*\\brel=)[^>]*)(?:[^ >]*)>/

  • Extract web page images:
  • /\\]*[ src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*)/

  • Thunder link:
  • /^thunder:\/\/[a-zA-Z0-9] =$/

  • ed2k link:
  • /^ed2k :\/\/|file|. |\/$/

  • linux "file" path:
  • /^\/(\w \/) \w \.\w $/

  • "File" path under window:
  • /^[a-zA-Z]:\\(?:\w \\ )*\w \.\w $/

life-related

    amount (loose, optional is negative, the first bit can be 0, supports thousandth separation):
  • /^-?\d (,\d{3})*(\.\d{1,2})?$/

  • Amount (greater than 0, two decimal places):
  • /(^[1-9]{1}[0-9]*$)|(^[0- 9]*\.[0-9]{2}$)/

  • Amount (strict, not negative, up to two decimal places, the first digit is not 0) :
  • /(^[1-9]([0-9] )?(\.[0-9]{1,2})?$)|(^(0){1}$)|( ^[0-9]\.[0-9]([0-9])?$)/

  • Passport:
  • /(^[EeKkGgDdSsPpHh] \d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa]) |(1[45]))\d{7}$)/

  • Hong Kong ID card:
  • /^[a-zA-Z]\d{ 6}\([\dA]\)$/

  • Macau ID card:
  • /^[1|5|7]\d{6}\( \d\)$/

  • Wanwan ID card:
  • /^[a-zA-Z][0-9]{9}$/

  • Stock code:
  • /^(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/7119242343798013959

More programming related For knowledge, please visit:

programming teaching

! !
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
PHP regular expression validation: number format detection PHP regular expression validation: number format detection Mar 21, 2024 am 09:45 AM

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

Master regular expressions and string processing in Go language Master regular expressions and string processing in Go language Nov 30, 2023 am 09:54 AM

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.

How to match timestamps using regular expressions in Go? How to match timestamps using regular expressions in Go? Jun 02, 2024 am 09:00 AM

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.

How to validate email address in Golang using regular expression? How to validate email address in Golang using regular expression? May 31, 2024 pm 01:04 PM

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.

How to verify password using regular expression in Go? How to verify password using regular expression in Go? Jun 02, 2024 pm 07:31 PM

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.

Chinese character filtering: PHP regular expression practice Chinese character filtering: PHP regular expression practice Mar 24, 2024 pm 04:48 PM

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 of fuzzy inclusions PHP regular expressions: exact matching and exclusion of fuzzy inclusions Feb 28, 2024 pm 01:03 PM

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.

PHP returns the string from the start position to the end position of a string in another string PHP returns the string from the start position to the end position of a string in another string Mar 21, 2024 am 10:31 AM

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