What is the difference between an extended regular expression and a regular expression when egrep or Grep-e uses an extended regular expression for text matching compared to grep?
1 Basic Regular Expressions:
Character Matching:
.: Any single character
[]: A single character in a character set such as [0-9] means any number of digits
[^]: a single character that is not part of a character set such as [^[:space:]] denotes any non-whitespace character
Number of matches:
*: Any time
\?: 0 or 1 times
\{m,n\}: At least m times, up to n times;
. *: Any character of any length
Anchoring:
^: Anchor at the beginning of the line
$: End of line anchoring
\<, \b: The head of the word
\>, \b: suffix
Tuple references:
\(\)
\1, \2, \3, ...
====================================================================================
2. Extended Regular Expressions
Character Matching:
.
[]
[^]
Number of matches:
*: Match the preceding character any number of times
?: matches the preceding character 0 or 1 times
+: Match the characters in front of it at least 1 times
{M,n} matches the preceding character at least m times, up to n times note: No more escaping than basic regular expressions
Location anchoring:
^ Beginning of the line
$ End of line
\< or \b # # # # words First
\> or ###\b ending
Meta-group:
(): Tuple Note: You do not need to escape from a basic regular expression
\1, \2, \3, ...
Or
|: OR
Note: This is a function of extended regular expressions. To grep support, you must use the GREP-E
Note: The content used for selection must be added to the parentheses
(c|c) At:cat or cat
C|cat:c or Cat
By comparison, the difference between a basic regular expression and an extended regular expression is that
1. On the number of matches, the extended regular expression is more than one + to match the preceding character at least once the equivalent of \{1,\}
2. Extended regular Expression {M,n} no longer needs to be escaped
3. Grouping of Extended regular expressions () also no longer needs to be escaped
4. Regular expressions have one more or |
Then we can consider using extended regular expressions when matching text patterns, avoiding the use of too many escape characters \
This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1826252
Linux Basics (10) on the difference between grep and egrep