Regular expressions
Example
phone number: 1[0-9]
grep -E "RunTime:[0-9]\.[1-9]" 20_08_18.log match: RunTime:0.149090s;
grep -E "Number\":\"[0-9]{4,}\"" 20_08_18.log match: Number":"10000180";
Three types of regex
The grep understands three different types of regular expression syntax as follows:
-
basic (BRE):
notethat: the metacharacters
( )and{ }be designated\(\)and\{\}; extended (ERE): add
?,+,|;perl (PCRE)
. dot matche any single character.
position
^ match the starting position of any line.
$ match the ending position of any line.
Quantification
* any number of matching character.
? zero or one occurrences of preceding element.
+ one or more occurrences of preceding element.
{n} the preceding item is matched exactly n times.
{min,} the preceding item is matched at least min times.
{min,max} the preceding item is matched at least min times but not more than max times.
() grouping. define the scope and precedence of operators.
REFERENCES: