Extended Regular Expressions __ regular expressions

Source: Internet
Author: User
Tags egrep


Remove the line from the beginning of the empty line grep-v ' ^$ ' a.txt | Grep-v ' ^# ' This requires a pipeline to search two times the following uses extended regular Expressions egrep-v ' ^$|^# ' a.txt
+ Repeat one or more characters search God good goood and other strings, o+ represents more than one o egrep-n ' go+d ' a.txt
? 0 or 1 characters to search GD or God string line Egrep-n ' Go?d ' a.txt
| Find a number of strings in or (or) egrep-n ' Gd|good ' a.txt find a line that contains a string of GD or God
() Find the rows that contain glad or good or Gaad or glod these two strings Egrep-n ' G (la|oo|aa|lo) ' A.txt
! is not a special character found in a regular expression contains (!) With (>) the line grep-n ' [!>] ' a.txt

RE characters Meaning and Paradigm
+ Repeat "one or more" of the previous RE characters
Example: Egrep-n ' Go+d ' regular_express.txt
Search (God) (good) (Goood) ... And so on the string. The o+ represents "more than one o" so the above results will be the 1th, 9, 13.
? The first RE character of "0 or one"
Example: Egrep-n ' Go?d ' regular_express.txt
Search (GD) (God) these two strings. That O? Represents "empty or 1 O" So, the above implementation will be the 13th, 14 ranks out.
It was found that the result set of these two cases (' go+d ' and ' go?d ') is the same as ' go*d '. Think about it, that's why OH. ^_^
| Find a number of strings in or (or)
Example: Egrep-n ' Gd|good ' regular_express.txt
Search for GD or good these two strings, note that is "or". So, the first three lines of 1,9,14 can be printed out oh. Well, what if you want to find dog? That's it:
Egrep-n ' Gd|good|dog ' regular_express.txt
( ) Find the "group" string
Example: Egrep-n ' G (la|oo) d ' regular_express.txt
Search for (glad) or (good) these two strings, because G and D are duplicates, so I can list LA and oo in () and take | To separate, it's OK.
In addition, this function can also be used as a "multiple repeating group" discriminant Oh. For example:
echo ' Axyzxyzxyzxyzc ' | Egrep ' A (xyz) +c '
In the example above, I'm going to look at the beginning of a, the end of A is C, the middle has more than one "xyz" string meaning ~

These are the special characters of the extended regular expression. In addition, the special emphasis is, that! In regular expressions it is not a special character, so if you want to find out what the file contains! With > lines, you can do this: Grep-n ' [!>] ' Regular_express.txt can you understand this? Often see the subject of a trap to write: "Reverse Select this to No." ' [!a-z] '. ", hehe. is wrong yo ~ to ' [^a-z] is right. Remove the line from the beginning of the empty line grep-v ' ^$ ' a.txt | Grep-v ' ^# ' This requires a pipeline to search two times the following uses extended regular Expressions egrep-v ' ^$|^# ' a.txt
+ Repeat one or more characters search God good goood and other strings, o+ represents more than one o egrep-n ' go+d ' a.txt
? 0 or 1 characters to search GD or God string line Egrep-n ' Go?d ' a.txt
| Find a number of strings in or (or) egrep-n ' Gd|good ' a.txt find a line that contains a string of GD or God
() Find the rows that contain glad or good or Gaad or glod these two strings Egrep-n ' G (la|oo|aa|lo) ' A.txt
! is not a special character found in a regular expression contains (!) With (>) the line grep-n ' [!>] ' a.txt

RE characters Meaning and Paradigm
+ Repeat "one or more" of the previous RE characters
Example:egrep-n ' go+d ' regular_express.txt
Search (God) (good) (Goood) ... And so on the string. The o+ represents "more than one o" so the above results will be the 1th, 9, 13.
? The first RE character of "0 or one"
Example:egrep-n ' go?d ' regular_express.txt
Search (GD) (God) these two strings. That O? Represents "empty or 1 O" So, the above implementation will be the 13th, 14 ranks out.
It was found that the result set of these two cases (' go+d ' and ' go?d ') is the same as ' go*d '. Think about it, that's why OH. ^_^
| Find a number of strings in or (or)
Example:egrep-n ' Gd|good ' regular_express.txt
Search for GD or good these two strings, note that is "or". So, the first three lines of 1,9,14 can be printed out oh. Well, what if you want to find dog? That's it:
Egrep-n ' Gd|good|dog ' regular_express.txt
( ) Find the "group" string
Example:egrep-n ' g (la|oo) d ' Regular_express.txt
Search for (glad) or (good) these two strings, because G and D are duplicates, so I can list LA and oo in () and take | To separate, it's OK.
In addition, this function can also be used as a "multiple repeating group" discriminant Oh. For example:
echo ' Axyzxyzxyzxyzc ' | Egrep ' A (xyz) +c '
In the example above, I'm going to look at the beginning of a, the end of A is C, the middle has more than one "xyz" string meaning ~

These are the special characters of the extended regular expression. In addition, the special emphasis is, that! In regular expressions it is not a special character, so if you want to find out what the file contains! With > lines, you can do this: Grep-n ' [!>] ' Regular_express.txt can you understand this? Often see the subject of a trap to write: "Reverse Select this to No." ' [!a-z] '. ", hehe. is wrong yo ~ to ' [^a-z] is right.

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.