Linux Basics (10) on the difference between grep and egrep

Source: Internet
Author: User
Tags egrep

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.