Among various commonly used tools,
Regular Expressions are similar but different.
The following table lists some common Regular Expressions and their differences.
There are always many projects and many omissions are required. Please point out the missing items.
The Perl regular expression is used as the benchmark, and different usages are marked in pink.
|
Grep 2.5.1 |
Egrep 2.5.1 |
Sed 3.02 Sed 4.07 |
Awk 3.1.1 |
Perl 5.8.0 |
Vim 1, 6.1 |
Javascript ?? |
Escape |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
Line Header |
^ |
^ |
^ |
^ |
^ |
^ |
^ |
End of line |
$ |
$ |
$ |
$ |
$ |
$ |
$ |
N {n} {m, n} {M ,}{, n} |
/{N /} |
{N} |
/{N /} |
{N} Or/{n/} Only defines -- POSIX or -- Re-interval valid (to be expressed} and {, when you have to use // {and //} without defining -- POSIX or -- Re-interval, {n} syntax cannot be used, //}/{And} {are synonymous |
{N} |
/{N /} |
{N} |
{0 ,} |
* |
* |
* |
* Or/*, (to express *, use //*) |
* |
* |
* |
{1 ,} |
/+ |
+ |
/+ |
+ Or/+, (to express +, use // +) |
+ |
/+ |
+ |
{0, 1} |
/? |
? |
/? |
? Or /?, (To express ?, Use //?) |
? |
/? |
? |
Any character |
. |
. |
. |
. Contain/n. |
./S after modification, contain/n |
. Division/n |
. Division/n |
(PAT) Match and obtain results |
/(Pat /) |
(PAT) |
/(Pat /) |
(PAT) or/(Pat/) (to express parentheses, use //(//)) |
(PAT) |
/(Pat /) |
(PAT) |
(? : Pat) matched but not returned |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
(? : Pat) |
Not Supported |
(? : Pat) |
(? = Pat) equal to pre-Query |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
(? = Pat) |
Not Supported |
(? = Pat) |
(?! Pat) unprecheck |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
(?! Pat) |
Not Supported |
(?! Pat) |
| Or |
/| |
| |
/| |
| Or/| (to express |, use // |) |
| |
/| |
| |
Any character |
[Xyz] |
[Xyz] |
[Xyz] |
[Xyz] |
[Xyz] |
[Xyz] |
[Xyz] |
[. Ch.] [= CH =] |
Not Supported |
Not Supported |
[. Ch.] |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
Word boundary/B |
/B |
/B |
/B |
Not Supported |
/B |
Not Supported |
/B |
Non-word boundary/B |
/B |
/B |
/B |
Not Supported |
/B |
Not Supported |
/B |
Left and right boundary of words <> |
/</> |
/</> |
/</> |
Not supported (> <and/>/<and //> // <synonymous |
Not supported (> <and/>/<synonymous |
/</> |
Not supported (> <and/>/<synonymous |
Control Character/CX |
Not Supported |
Not Supported |
/CX |
Not Supported |
/CX |
Not Supported |
/CX |
Number/d |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
/D |
/D |
/D |
Non-numeric/d |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
/D |
/D |
/D |
Form feed/F |
Not Supported |
Not Supported |
High Version support |
/F |
/F |
Other meanings/F indicates the file name characters |
/F |
Line feed/n |
Not Supported |
Not Supported |
Not Supported |
/N |
/N |
/N |
/N |
Press enter/R |
Not Supported |
Not Supported |
/R |
/R |
/R |
/R |
/R |
Blank/s |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
/S |
/S |
/S |
Non-blank/s |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
/S |
/S |
/S |
Tab/T |
Not Supported |
Not Supported |
High Version support |
/T |
/T |
/T |
/T |
Vertical TAB/V |
Not Supported |
Not Supported |
High Version support |
/V |
/V |
Very magic |
/V |
Word character/W [A-Za-z0-9 _] |
/W |
/W |
/W |
Not Supported |
/W |
/W |
/W |
Non-word character/W [^ A-Za-z0-9] |
/W |
/W |
/W |
Not Supported |
/W |
/W |
/W |
/XN hexadecimal |
Not Supported |
Not Supported |
High Version support |
/XN |
/XN |
Otherwise, X indicates [0-9a-za-z]. |
/XN |
/N octal |
Not Supported |
Not Supported |
Not Supported |
/N |
/N |
Not Supported |
/N |
/N Back Reference |
/N |
/N |
/N |
/N. Only the result is available. |
/N |
/N. Only the result is available. |
/N |
[: Alnum:] letters and numbers |
[: Alnum:] |
[: Alnum:] |
[: Alnum:] |
[: Alnum:] |
[: Alnum:] |
[: Alnum:] |
Not Supported |
[: Alpha:] letters |
[: Alpha:] |
[: Alpha:] |
[: Alpha:] |
[: Alpha:] |
[: Alpha:] |
[: Alpha:] |
Not Supported |
[: Cntrl:] control characters |
[: Cntrl:] |
[: Cntrl:] |
[: Cntrl:] |
[: Cntrl:] |
[: Cntrl:] |
[: Cntrl:] |
Not Supported |
[: Digit:] Number |
[: Digit:] |
[: Digit:] |
[: Digit:] |
[: Digit:] |
[: Digit:] |
[: Digit:] |
Not Supported |
[: Graph:] printable characters (excluding spaces) |
[: Graph:] |
[: Graph:] |
[: Graph:] |
[: Graph:] |
[: Graph:] |
[: Graph:] |
Not Supported |
[: Lower:] lower case |
[: Lower:] |
[: Lower:] |
[: Lower:] |
[: Lower:] |
[: Lower:] |
[: Lower:] |
Not Supported |
[: Print:] printable characters (including spaces) |
[: Print:] |
[: Print:] |
[: Print:] |
[: Print:] |
[: Print:] |
[: Print:] |
Not Supported |
[: Punct:] punctuation |
[: Punct:] |
[: Punct:] |
[: Punct:] |
[: Punct:] |
[: Punct:] |
[: Punct:] |
Not Supported |
[: Space:] Space |
[: Space:] |
[: Space:] |
[: Space:] |
[: Space:] |
[: Space:] |
[: Space:] |
Not Supported |
[: Upper:] uppercase letters |
[: Upper:] |
[: Upper:] |
[: Upper:] |
[: Upper:] |
[: Upper:] |
[: Upper:] |
Not Supported |
[: Xdigit:] hexadecimal number |
[: Xdigit:] |
[: Xdigit:] |
[: Xdigit:] |
[: Xdigit:] |
[: Xdigit:] |
[: Xdigit:] |
Not Supported |
[: Return:] |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
[: Return:] |
Not Supported |
[: Tab:] |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
[: Tab:] |
Not Supported |
[: Escape:] |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
[: Escape:] |
Not Supported |
[: Backspace:] |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
Not Supported |
[: Backspace:] |
Not Supported |
Http://blog.chinaunix.net/space.php? Uid = 374372 & Do = Blog & cuid = 351427
Source: