Linux Regular Expressions and Regular Expressions
Basic Regular Expression
^ The string to be searched by word starts with word
Grep-n "^ a" regex.txt find the row whose first character is a and output the row number
Word $ the string to be searched ends with word
Grep-n "a $" regex.txt searches for the rows ending with a and outputs the row number
Grep-n "^ $" regex.txt searches for empty rows and outputs row numbers
. Represents any single character, including Spaces
\ Escape characters
* Repeat zero to infinite first characters
[List] For example, p [abc] d matches pad, pbd, and pcd.
[^ List] is opposite to [list], excluding any
[N1-n2] For example: [0-9] or [a-z] or [A-Z] represents any one in the range
Grep-n "9 [0-9]" regex.txt matches 90, 91 ...... 99
The first character of \ {n, m \} is n to m, for example, a \ {3, 5 \} matches aaa, aaaa, or aaaaa.
Grep-n "go \ {1, 2 \} d" regex.txt matched string is good god
The first character of \ {n, \} must be at least n times.
Grep-n "go \ {2, \} d" regex.txt matched string is good goood gooood...
Extended Regular Expression
+ Repeat the previous RE character at least once
? 0 or 1 time before a RE character
| Or
() As a group in parentheses
() + Repeated Group
\<\< Line whose abc starts with abc
\> Abc \> rows ending with abc