General Regular Expression
Translator: Zhang guiquan
(From the regular expression pocket manual. Translator, Zhang guiquan. Download the translated version from http://download.csdn.net/source/410896)
This section contains simple General Regular Expression Patterns. You may need to make necessary adjustments to meet your needs.
Here, only the target strings and unmatched strings matching each expression are given. You may need to make necessary adjustments to meet your needs.
Written in the Perl style:
/Mode/Form
S/Mode/replacement/Form
Tips
Remove leading and trailing Spaces
S/^/S + //
S // s + $ //
Match: "foo bar" and "foo"
Mismatch: "foo bar"
A number between 0 and 999999
/^/D {1, 6} $/
Matching: 42 and 678234
Mismatch: 10,000 (10 thousand with delimiters)
Verify the hexadecimal encoding of HTML
/^ # ([A-fA-F0-9]) {3} ([a-fA-F0-9]) {3 })? $/
Matching: # fff ,# 1a 1, #996633
Mismatch: # ff and ffffff
American Social Security Code
/^/D {3}-/d {2}-/d {4} $/
Matching: 078-05-1120
Mismatch: 078051120 and 1234-12-12
US Postal code
/^/D {5} (-/d {4 })? $/
Matching: 94941-3232 and 10024
Mismatch: 949413232
US currency
/^/$/(D {1, 3} (/,/d {3}) * |/d +) (/./d {2 })? $/
Matching: $20 and $15,000.01
Mismatch: $1.001 and $. 99
Matching date mm/DD/YYYY hh: mm: SS
/^/D:/D/d $/
Matching: 04/03/1978 20:45:38
Mismatch: 4/03/1978 20:45:38 and 4/3/78
Leading path name
/^ .*///
Match:/usr/local/bin/apachectl
Mismatch: C: // system/foo.exe
(See MRE 190-192)
Point-to-Point IP Address
/^ (/D | [01]? /D/d | 2 [0-4]/d | 25 [0-5])/.
(/D | [01]? /D/d | 2 [0-4]/d | 25 [0-5])/.
(/D | [01]? /D/d | 2 [0-4]/d | 25 [0-5])/.
(/D | [01]? /D/d | 2 [0-4]/d | 25 [0-5])$/
Matching: 127.0.0.1 and 224.22.5.110
Mismatch: 127.1
(See MRE 187-189)
MAC address
/^ ([0 -9A -Fa-F] {2 }:{ 5} [0 -9A -Fa-F] {2} $/
Match: 01: 23: 45: 67: 89: AB
Mismatch: 01: 23: 45 and 0123456789ab
Email
/^ [0 -9A -Za-Z] ([-./W] * [0-9 minutes-Za-Z _ +]) * @ ([0 -9A -Za-Z] [-/W] *
[0 -9A -Za]/.) + [A-Za-Z] {2, 9} $/
Match: tony@example.com, tomnu@i-e.com, and tony@mail.example.museum
Mismatch:. @ example.com, tony@i-.com, and tony@example.a
(See MRE 70)
HTTP URL
/(HTTP ?) : // ([0 -9A -Za-Z] [-/W] * [0 -9A -Za-Z]/.) +
[A-Za-Z] {2, 9 })
(:/D {1, 4 })? ([-/W //#~ :.? + = & % @ ~] *)/
Match: https://example.com and http://foo.com: 8080/bar.html
Mismatch: ftp://foo.com and ftp://foo.com/