Collection of regular expression examples, learn regular expressions through examples. This warehouse example collection comes from "Some Regular Expression Notes" , through a separate warehouse to organize these regular examples, and provide a example website , which is convenient for regular example verification and query. It is also convenient for add new regular examples to maintain together.
domestic mirror site🇨🇳 · Gitee · Github
If you have some basic knowledge and understand through examples, you will get started more quickly and write your own rules. If you are not familiar with the basics, you can through 16196718adc896 16196718adc897 "Learn regex the easy way" , this warehouse tutorial has been translated into more than a dozen languages, including Chinese translation , it is very simple Examples to help you understand the basic grammar rules of regular.
Example
ID number
^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$
🚧 E.g: 42112319870115371X
username
^[a-zA-Z0-9_-]{4,16}$
🚧 Eg: jaywcjlove
. Verify digital , letters , _ , - , does not contain special characters, the length 4-16
between.
We chat number
^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$
🚧 Eg: jslite
. Wechat regular, 6 to 20 digits, starting with a letter, letter, number, minus sign, underscore.
Password strength (loose)
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
🚧 Eg: diaoD123
, Wgood123
. It must be letters and numbers , and the length is between 8-10
.
^[0-9a-zA-Z\u4E00-\uFA29]*$
🚧 Eg: diaoD123
, Wgood123
. Digit alphabet Chinese.
Password strength (including special characters)
^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$
🚧 Eg: diaoD123#
, Wgood123#$
. The password strength is regular, at least 6
characters, including at least 1
uppercase letters , 1
lowercase letters , 1
numbers 1
.
Train number
^[GCDZTSPKXLY1-9]\d{1,4}$
E.g: G2868
, D22
, D9
, Z5
, Z24
, Z17
Chinese Characters
^[\u4e00-\u9fa5]{0,}$
🚧 Eg: Chinese,
Hubei,
Huanggang. There is no limit to the length of the text.
^[\u4e00-\u9fa5]{2,6}$
🚧 Eg: Chinese,
Huanggang, Hubei. 2 to 6 Chinese characters
Chinese name
^(?:[\u4e00-\u9fa5·]{2,16})$
🚧 Eg: Jay Chou,
Gurina Zal Baihetiar,
Rashid bin Mohammed bin Rashid.
English name
(^[a-zA-Z][a-zA-Z\s]{0,20}[a-zA-Z]$)
🚧 E.g: Gene Kelly
, Fred Astaire
, Humphrey Bogart
, GaryCooper
, Cary Grant
, Joan Crawford
URL
^[a-zA-Z]+:\/\/
🚧 E.g: http://www.abc.com
, http://
, https://
^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$
🚧 E.g: https://github.com
, https://github.com/jaywcjlove
^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$
🚧 E.g: blog.csdn.net
Mac address matching
^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$
🚧 E.g: dc:a9:04:77:37:20
Picture suffix
(.jpg|.gif|.png|.jpeg)+(\?|\#|$)
🚧 E.g: a/b/c.jpg?
, a/b/c.png
, a/b/c.png?good=1
fax number
^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$
🚧 Eg: 086-021-5055452
, 021-5055452
. Country code (2 to 3 digits), area code (2 to 3 digits), telephone number (7 to 8 digits), extension number (3 digits)
mobile phone number
^1[34578]\d{9}$
🚧 E.g: 13611778887
^((\+?[0-9]{1,4})|(\(\+86\)))?(13[0-9]|14[57]|15[012356789]|17[03678]|18[0-9])\d{8}$
🚧 E.g: 13611779993
, +8613611779993
<details>
<summary>Example & detailed description</summary>
- 13 segments: 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
- Segment 14: 145, 147
- 15 segments: 150, 151, 152, 153, 155, 156, 157, 158, 159
- Segment 17: 170, 176, 177, 178
- 18 segments: 180, 181, 182, 183, 184, 185, 186, 187, 188, 189
- International code such as: China (+86)
</details>
IPv4 address
(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}
🚧 E.g: 192.168.1.1
, 127.0.0.1
, 0.0.0.0
, 255.255.255.255
, 1.2.3.4
^(?:(?: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]?)$
🚧 E.g: 192.168.1.1
, 127.0.0.1
, 0.0.0.0
, 255.255.255.255
, 1.2.3.4
IPv6
(([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]))
🚧 E.g: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
, FE80:0000:0000:0000:0202:B3FF:FE1E:8329
。
^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$
🚧 E.g: wowohoo@qq.com
^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$
🚧 E.g: wowohoo@qq.com
<details>
<summary>Examples & Detailed Description</summary>
- The mailbox starts with az, AZ, 0-9, and the minimum length is 1.
- If the left part contains -, _,., these special symbols must be preceded by a number or letter.
- @ Symbol is required
- The right part can be divided into two parts. The first part is the domain name address of the mail provider, and the second part is the domain name suffix. The shortest known number is 2 digits.
The longest is 6 for. - The mail provider domain can contain special characters -, _,.
</details>
Hexadecimal color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
🚧 E.g: #b8b8b8
, #333
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
🚧 E.g: #b8b8b8
, #333
date
^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$
🚧 Eg: 2017-02-29
. For month and date verification.
version number
^\d+(?:\.\d+){2}$
🚧 Eg: 0.1.2
. The format must be X.Y.Z
.
number plate
^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](?:((\d{5}[A-HJK])|([A-HJK][A-HJ-NP-Z0-9][0-9]{4}))|[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳])$
🚧 Eg: E A34324,
Shanghai E13359F. Contains new energy license plate.
^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$
🚧 Eg: E A34324,
Shanghai E13595. Does not include new energy license plate.
A few digits after the decimal point
^[0-9]+(.[0-9]{2})?$
🚧 Eg: 1.22
, 0223.23
. Accurate to 2
decimal places
Decimal
^\d+\.\d+$
🚧 E.g: 0.0
, 0.23
, 10.54
。
(-?\d+)(\.\d+)?
🚧 E.g: -0.0
, 0.23
, -10.54
。
Positive integer
[0-9]*[1-9][0-9]*
🚧 E.g: 23
Negative integer
-[0-9]*[1-9][0-9]*
🚧 E.g: -23
, -2.34
Integer
-?\d+
🚧 E.g: 23
, 12
, -12.55
Non-negative integer (positive integer or zero)
\d+
🚧 E.g: 23
, 3.322
number
^\d{1,}$
🚧 Eg: 0120
, 234234
. Do not include decimals.
^\d{32}$
🚧 Eg: 12232324444757575757575757575759
. 32 is a pure number.
Number (QQ number)
^[1-9][0-9]{4,10}$
🚧 Eg: 398188661
. Regular QQ number, 5 to 11 digits.
^\d{5,11}$
🚧 Eg: 398188661
. A simpler QQ number regular, composed of 5 to 11 digits.
Chinese postal code
[1-9]\d{5}(?!\d)
🚧 Eg: 200000
. Chinese postal codes are 6 digits.
English alphabet
^[A-Z]+$
🚧 Eg: ABC
, WANG
. Capital English letters.
^[a-z]+$
🚧 Eg: abc
, wang
. Lowercase English letters.
(^[a-z]|[A-Z0-9])[a-z]*
🚧 Eg: Tests
, JavaScript
, RegEx
. Big hump.
The port number
^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$
🚧 E.g: 8080
,3000
,65535
Thunder Link
^thunderx?:\/\/[a-zA-Z\d]+=$
🚧 E.g: 8080
。
ed2k link
^ed2k:\/\/\|file\|.+\|\/$
🚧 E.g: ed2k://|file|[xxx.com][%E8%8B%B1%E9%9B%84%E6%9C%AC%E8%89%B23.mp4|/
。
Magnet link
^magnet:\?xt=urn:btih:[0-9a-fA-F]{40,}.*$
🚧 E.g: magnet:?xt=urn:btih:608FA22181A2614BAE9160763F04FCB7ED296B9E
time
^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$
🚧 Eg: 21:54:55
, 00:23:23
. 24
hour format time format HH:mm:ss
, and verify the time.
^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$
🚧 Eg: 12:54:55
, 01:23:23
. 12
hour format time format HH:mm:ss
, and verify the time.
HTML markup
<(\S*?)[^>]*>.*?</\1>|<.*?/>
🚧 E.g: <div>title</div>
, <head>title</head>
。
Tool recommendation
- RegExp online regular expression learning tool.
- Regulex *%3F%24) JavaScript regular expression visualization tool.
- Rubular Ruby regular expression editor.
- Regex101 multi-language support, build, debug and share regular.
- Regexper regular expression visualization tool.
- RegEx Pal regular expression debugging and practice examples.
- Regular Expression Tester online regular expression tester.
- iHateRegex regular expression cheat sheet.
- Learn regular expressions in a simple way
- Expressions APP regular expression application for Mac
License
Licensed under the MIT License.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。