regular notation

1. What is regular notation?
Regular notation is a method of processing strings. It processes strings in line units. With the help of some special symbols, regular notation allows users to easily achieve [Search/ Remove/replace] a handler for a specific string.
2. Basic regular notation
   2.1 Use square brackets [] to search for set characters
      In fact, no matter how many characters there are in [], it only represents a certain character.
   2.2 Line start and line end characters ^ $
    Note: The ^ symbol is different inside and outside the character set symbol (brackets []). Inside the [] represents the reverse selection, and outside the [] represents the meaning of positioning at the beginning of the line. $ means positioning at the end of the line.
   2.3 Any character. and repeated characters *
    - . (decimal point): means that there must be an arbitrary character
    - * (asterisk): means repeating the previous 0 to infinite times, which is a combined form-
    .*: means Zero or more arbitrary characters
   2.4 Restricting the range of consecutive RE characters {}
   The basic regular notation special characters are assembled as follows:
   ^word : the string to be searched for word at the beginning of the line
   word$: the string to be searched for word at the end of the line
   .: Represents [there must be an arbitrary character] character
   \: Removes the special meaning of special symbols
   *: Repeats zero to infinity of the previous RE character
   [list]: The RE character of the character set, which lists the desired RE characters Extracted characters  
   [n1-n2]: Character set RE characters, which lists the range of characters you want to extract
   [^list]: RE characters of the character set, which list unnecessary strings or ranges
   \{n,m\}: the previous RE character of n to m consecutive characters
   \{n,\}: consecutive N characters or more the previous RE character

 

3. Extended Regular Notation

For example, if we want to remove the blank lines and the lines starting with # in the regular_express.txt file, we use grep -v '^$' regular_express.txt|grep -v '^#', we need to use the pipeline command to search for two Second-rate. Then if extended regular notation is used, it can be simplified to:

egrep -v '^$|^#' regular_express.txt

Special symbols for extended regular notation:

+ : Repeat one or more of the previous RE characters

? : zero or one money one RE character

|: Use OR to find several strings

(): find the group string

()+: Discrimination of multiple repeating groups

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326427437&siteId=291194637