Linux Regular Expression 1. Some special symbols 2. First-line control character ^, last-line control character $ [html] Find the first rule containing the: [root @ www ~] # Grep-n' ^ the 'regular_express.txt starts with a lowercase letter: # grep-n' ^ [a-z] 'regular_express.txt. If I do not want to start with an English letter: # grep-n' ^ [^ a-zA-Z] 'regular_express.txt is not started with an English letter: [root @ www ~] # Grep-n' ^ [^ a-zA-Z] 'regular_express.txt shows a blank line: [root @ www ~] # Grep-n '^ $' regular_express.txt do not display blank rows and rows with # signs: # grep-v '^ $'/etc/syslog. conf | grep-v '^ #' 3. in the regular expression. ". "Represents an absolute meaning of any character, and" * "represents repeating the meaning of the previous one to infinity. [cpp] searches for four characters starting with g and ending with d: # grep-n'g .. d 'regular_express.txt looks for oo, ooo, oooo, and so on, that is, there must be at least two o: # grep-n 'ooo * 'regular_express.txt (the first two o must exist, the third o repeat is unlimited.) Search for strings starting with g and ending with g. The strings can be unavailable in the middle. [root @ www ~] # Grep-n 'G. * G' regular_express.txt what do I do if I want to find two to five consecutive o strings? At this time, you have to use a limited range of characters. But {} has special significance in shell. You must use the Escape Character \ To make it meaningless. The syntax of limit {} is as follows. Suppose I want to find two o strings, which can be: [root @ www ~] # Grep-n'go \ {2, 5 \} G' regular_express.txt 4. special characters in regular expressions (1) ^ word: the string to be searched (word) at the beginning of the line! Search for "#": grep-n' ^ # 'regular_express.txt (2) word $: set the end of the line! When the line of "!" is printed out, the "!" line is listed in "!". Ending with: grep-n '! $ 'Regular_express.txt (3) \: remove the special symbol "alias! Search for the line where T has single quotation marks: grep-n \ 'regular_express.txt (4) *: repeat zero to infinite bytes and search for the beginning of es with the first character, the following s repeats more than two times: grep-n 'ess * 'regular_express.txt (5) [list]: Character Set RE character, which lists the characters you want to select! Search for lines of gl or gd: grep-n 'g [ld]' regular_express.txt (6) Character Set combined with RE characters, which lists strings that do not match the range! The searched string can be (oog) (ood) but not (oot): rep-n 'oo [^ t] 'regular_express.txt (7) [n1-n2]: character Set, which lists the range of characters you want to include! Search for: grep-n '[0-9]' regular_express.txt (8) \ {n, m \} with numbers \}: search for strings with 2 to 3 o between n to m consecutive "First RE character" and g without g: grep-n 'go \ {2, 3 \} G' regular_express.txt