美文网首页
Regular expressions

Regular expressions

作者: 黄耀鸿 | 来源:发表于2020-08-21 19:39 被阅读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:

  • 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/

相关文章

网友评论

      本文标题:Regular expressions

      本文链接:https://www.haomeiwen.com/subject/qaspjktx.html