Linux Regular Expressions-selective operations and grouping operations

Source: Internet
Author: User

Selective operation
Vertical bar (|) Characters are part of a meta-character extension set that specifies the Union of regular expressions. If a row matches one of the regular expressions, it matches the pattern. For example, the regular expression: unix| Linux
The line that contains the string "UNIX" or the string "LINUX" will be matched. You can specify more choices, such as:
Unix| Linux| NETBSD

When using Egrep, prints a line that matches any of these 3 modes.
In sed, there are no union metacharacters, and each mode can be specified separately. In the following, we will consider the operations of the grouping, and we will see additional columns about the metacharacters.

grouping operations The
parentheses () are used to group and prioritize regular expressions. They are part of the meta-character expansion set. Suppose the name of the company in the text file is "Bigone" or "Bigone computer", using an expression:
Bigone (computer)?

Matches the string "Bigone" itself or follows the form of a string "computer". Similarly, some terms are sometimes used in full spelling, sometimes abbreviated, and can be used:
$ egrep "Lab (oratorie)? s" Mail.list
Bell Laboratories, Lucent Technologies
Bell Labs
You can use vertical bars and parentheses to group selective operations. In the following example, we use it to specify a singular or plural match to the word "Company".

Compan (y|ies)
Note that in most sed and grep versions, you cannot apply a number of words to a set of parentheses, but are available in all versions of Egrep and awk.

Reference: http://www.linuxawk.com/communication/455.html

Linux Regular Expressions-selective operations and grouping operations

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.