Regular expressions

2020-08-21  本文已影响0人  黄耀鸿

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:

. 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:

https://www.cyberciti.biz/faq/grep-regular-expressions/

上一篇 下一篇

猜你喜欢

热点阅读