Regular expressions

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:

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。