Skip to content

Latest commit

 

History

History
267 lines (189 loc) · 9.86 KB

POSIX.md

File metadata and controls

267 lines (189 loc) · 9.86 KB

POSIX Standard Regular Expressions

Regular expressions mainly have PCRE and POSIX two standards, The POSIX standard has five flavors: BRE (Basic Regular Expressions), GNU BRE, ERE (Extended Regular Expressions), GNU ERE, and the deprecated SRE (Simple Regular Expressions). The syntax is not consistent between each other.

Since the PCRE standard is widely supported by various popular programming languages, the regular expressions in this project are all PCRE. The POSIX standard is currently supported primarily by various Unix-like system built-in commands, such as awk, sed and other commands in Linux.

Due to the large number of Unix-like systems and a long history, there are many implementation versions of the same command (for example, awk has many implementations such as awk, gawk, mawk, nawk), they may use different flavors and it's difficult to be compatible with all flavors and commands. Therefore, the regular expressions listed in this document are only compatible with the following two flavors:

  • GNU BRE (gsed - GNU sed)
  • GNU ERE (gawk - GNU awk, ggrep - GNU grep)

Read more about regular expression standards in Wikipedia - Regular expression.

Regular Expressions

Match all numbers (Phone number + IoT number + Data only number)

Command Regular Expression
GNU ERE ^(+?86)?1(3[0-9]{3}|5[01235-9][0-9]{2}|8[0-9]{3}|7([0-35-9][0-9]{2}|4(0[0-9]|1[0-2]|9[0-9]))|9[0-35-9][0-9]{2}|6[2567][0-9]{2}|4((10|4[01])[0-9]{3}|[68][0-9]{4}|[579][0-9]{2}))[0-9]{6}$
GNU BRE ^\(+\?86\)\?1\(3[0-9]\{3\}\|5[01235-9][0-9]\{2\}\|8[0-9]\{3\}\|7\([0-35-9][0-9]\{2\}\|4\(0[0-9]\|1[0-2]\|9[0-9]\)\)\|9[0-35-9][0-9]\{2\}\|6[2567][0-9]\{2\}\|4\(\(10\|4[01]\)[0-9]\{3\}\|[68][0-9]\{4\}\|[579][0-9]\{2\}\)\)[0-9]\{6\}$

Match all numbers with SMS (Phone number + Data only number)

Command Regular Expression
GNU ERE ^(+?86)?1(3[0-9]{3}|5[01235-9][0-9]{2}|8[0-9]{3}|7([0-35-9][0-9]{2}|4(0[0-9]|1[0-2]|9[0-9]))|9[0-35-9][0-9]{2}|6[2567][0-9]{2}|4[579][0-9]{2})[0-9]{6}$
GNU BRE ^\(+\?86\)\?1\(3[0-9]\{3\}\|5[01235-9][0-9]\{2\}\|8[0-9]\{3\}\|7\([0-35-9][0-9]\{2\}\|4\(0[0-9]\|1[0-2]\|9[0-9]\)\)\|9[0-35-9][0-9]\{2\}\|6[2567][0-9]\{2\}\|4[579][0-9]\{2\}\)[0-9]\{6\}$

Mobile phone number

Match all

Command Regular Expression
GNU ERE ^(+?86)?1(3[0-9]{3}|5[01235-9][0-9]{2}|8[0-9]{3}|7([235-8][0-9]{2}|4(0[0-9]|1[0-2]|9[0-9]))|9[0-35-9][0-9]{2}|66[0-9]{2})[0-9]{6}$
GNU BRE ^\(+\?86\)\?1\(3[0-9]\{3\}\|5[01235-9][0-9]\{2\}\|8[0-9]\{3\}\|7\([235-8][0-9]\{2\}\|4\(0[0-9]\|1[0-2]\|9[0-9]\)\)\|9[0-35-9][0-9]\{2\}\|66[0-9]\{2\}\)[0-9]\{6\}$

Match China Mobile

Command Regular Expression
GNU ERE ^(+?86)?1(3(4[0-8]|[5-9][0-9])|5[012789][0-9]|7[28][0-9]|8[23478][0-9]|9[578][0-9])[0-9]{7}$
GNU BRE ^\(+\?86\)\?1\(3\(4[0-8]\|[5-9][0-9]\)\|5[012789][0-9]\|7[28][0-9]\|8[23478][0-9]\|9[578][0-9]\)[0-9]\{7\}$

Match China Unicom

Command Regular Expression
GNU ERE ^(+?86)?1(3[0-2]|[578][56]|66|96)[0-9]{8}$
GNU BRE ^\(+\?86\)\?1\(3[0-2]\|[578][56]\|66\|96\)[0-9]\{8\}$

Match China Telecom

Command Regular Expression
GNU ERE ^(+?86)?1(3(3[0-9]|49)[0-9]|53[0-9]{2}|8[019][0-9]{2}|7([37][0-9]{2}|40[0-5])|9[0139][0-9]{2})[0-9]{6}$
GNU BRE ^\(+\?86\)\?1\(3\(3[0-9]\|49\)[0-9]\|53[0-9]\{2\}\|8[019][0-9]\{2\}\|7\([37][0-9]\{2\}\|40[0-5]\)\|9[0139][0-9]\{2\}\)[0-9]\{6\}$

Match China Broadcast Network

Command Regular Expression
GNU ERE ^(+?86)?192[0-9]{8}$
GNU BRE ^\(+\?86\)\?192[0-9]\{8\}$

Match Inmarsat (Satellite Communications)

Command Regular Expression
GNU ERE ^(+?86)?1749[0-9]{7}$
GNU BRE ^\(+\?86\)\?1749[0-9]\{7\}$

Match Emergency Communication Support Center of MIIT (Emergency communications)

Command Regular Expression
GNU ERE ^(+?86)?174(0[6-9]|1[0-2])[0-9]{6}$
GNU BRE ^\(+\?86\)\?174\(0[6-9]\|1[0-2]\)[0-9]\{6\}$

MVNO number

Match all

Command Regular Expression
GNU ERE ^(+?86)?1(7[01]|6[257])[0-9]{8}$
GNU BRE ^\(+\?86\)\?1\(7[01]\|6[257]\)[0-9]\{8\}$

Match China Mobile

Command Regular Expression
GNU ERE ^(+?86)?1(65[0-9]|70[356])[0-9]{7}$
GNU BRE ^\(+\?86\)\?1\(65[0-9]\|70[356]\)[0-9]\{7\}$

Match China Unicom

Command Regular Expression
GNU ERE ^(+?86)?1(70[4789]|71[0-9]|67[0-9])[0-9]{7}$
GNU BRE ^\(+\?86\)\?1\(70[4789]\|71[0-9]\|67[0-9]\)[0-9]\{7\}$

Match China Telecom

Command Regular Expression
GNU ERE ^(+?86)?1(70[012]|62[0-9])[0-9]{7}$
GNU BRE ^\(+\?86\)\?1\(70[012]\|62[0-9]\)[0-9]\{7\}$

IoT number

Match all

Command Regular Expression
GNU ERE ^(+?86)?14([14]0|41|[68][0-9])[0-9]{9}$
GNU BRE ^\(+\?86\)\?14\([14]0\|41\|[68][0-9]\)[0-9]\{9\}$

Match China Mobile

Command Regular Expression
GNU ERE ^(+?86)?14(4[01]|8[0-9])[0-9]{9}$
GNU BRE ^\(+\?86\)\?14\(4[01]\|8[0-9]\)[0-9]\{9\}$

Match China Unicom

Command Regular Expression
GNU ERE ^(+?86)?146[0-9]{10}$
GNU BRE ^\(+\?86\)\?146[0-9]\{10\}$

Match China Telecom

Command Regular Expression
GNU ERE ^(+?86)?1410[0-9]{9}$
GNU BRE ^\(+\?86\)\?1410[0-9]\{9\}$

Data only number

Match all

Command Regular Expression
GNU ERE ^(+?86)?14[579][0-9]{8}$
GNU BRE ^\(+\?86\)\?14[579][0-9]\{8\}$

Match China Mobile

Command Regular Expression
GNU ERE ^(+?86)?147[0-9]{8}$
GNU BRE ^\(+\?86\)\?147[0-9]\{8\}$

Match China Unicom

Command Regular Expression
GNU ERE ^(+?86)?145[0-9]{8}$
GNU BRE ^\(+\?86\)\?145[0-9]\{8\}$

Match China Telecom

Command Regular Expression
GNU ERE ^(+?86)?149[0-9]{8}$
GNU BRE ^\(+\?86\)\?149[0-9]\{8\}$