Skip to content

Practical Regular Expressions

Match the line containing a specific string (string):

^(.*)string(.*)\n

Strict mobile phone number:

/^1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/

Loose mobile phone number:

/^1[3-9]\d{9}$/

Domestic landline phone number:

/^\d{3}-\d{8}|\d{4}-\d{7}$/

Landline phone number (including Hong Kong, Macau, and Taiwan):

/^(\d{3}-\d{8})|(\d{4}-\d{7})|(852|853|886-\d{7,8})$/

Email address:

/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](https://github.com/wqjiao/regular-set/blob/master?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](https://github.com/wqjiao/regular-set/blob/master?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

ID card number:

/^\d{6}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

Passport number (including Hong Kong and Macau):

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

License plate number (new energy + non-new energy):

/^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF](https://github.com/wqjiao/regular-set/blob/master/[A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9 挂学警港澳]{1})$/

New energy license plate number:

/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$/

Non-new energy license plate number:

/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/

Vehicle identification number:

/^[A-Z0-9]{17}$/

Engine number:

/^[A-Z0-9]{6,17}$/

Chinese postal code:

/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/

Allow alphanumeric and underscore combinations:

/^[a-zA-Z0-9_]{6,16}$/

Chinese characters:

/^[\u4E00-\u9FA5]+$/

English letters:

/^[a-zA-Z]+$/

Numbers:

/^\d{1,}$/

Decimal numbers:

/^\d+\.\d+$/

Cannot contain Chinese characters:

/^[^\u4E00-\u9FA5]*$/

This post is translated using ChatGPT, please feedback if any omissions.