Get the App
SLTechnology News&Howtos  ›  Development  › 

What is a grep regular expression?

Shulou Source: shulou.com Published: 2022-06-01 14:21:55 09月27日 Update

This article mainly shows you "what is grep regular expression", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is grep regular expression" this article.

A regular expression is just a description of a string, and string processing can only be done in combination with tools that support regular expressions.

Grep matching pattern

Grep accepts options and parameters as follows (where regex represents a regular expression)

‎ W. Grep [option] Regex [file] ‎

Options is mainly the following table:

Option meaning function description-i ignore case ignores case-v invert match mismatches-l file-with-match output matched file names-L file-without-match output mismatched file names-number of c count output matches (lines)-n number output matches lines while adding the file name and the number of lines in the file name-h no-filename suppresses the output of the file name

Suppose there are three files-del1, del2, del3-the contents are as follows

Examples

Getting started with grep regular expressions in Linux getting started with grep regular expressions in Linux

Special character

Symbolic meaning example ^ start mark "^ abc" satisfy example abc, abcd^ not (in []) "[^ abc]" satisfy example: ddd, mpd$ end tag "abc$" satisfy example abc, mmabc. Any character "A.C" satisfies the examples abc, fapcc\ "\ matches the word ending" abc\ > "abc, pmrabc | or" AAA | BBB "satisfies the examples AAA, BBBpp

Range

Examples of symbolic meaning? Match the previous character 0 or 1 time "abc?" Satisfied examples ab and mabcd* match previous character ≥ 0 times "abc*" examples abbb and abcdk+ match previous character ≥ 1 times "abc+" examples abcd, abcccdd {} {m}, {m,}, {m,}, { N} is the example abcccc or abcccccc that matches the previous character m times, m to n times, ≥ m times, ≤ n times "abc\ {3jue 5\}", respectively, if it is not in the range. Choose one. If it is a range, select one of the examples satisfied by "m [ABC] p" in the range, acpd;m [1-9] p satisfied example m8pp (), put all the elements of the candidate in (), and use | separate the examples a1bc and mba3bcd satisfied by "a (1 | 2 | 3) bc".

Note: {} needs to be transferred in the Zheng expression, but {} () does not.

Note the example of understanding the {} scope:

Standard character class

Character class defines [: alnum:] letters and numbers, equivalent to [A-Za-z0-9] [: word:] [: alnum:] and underscore _ [: alpa:] letters, equivalent to [A-Za-z] [: digit:] numbers, equivalent to [0-9] equivalent to [: xdigit:] hexadecimal characters, equivalent to [0-9A-Fa-f equivalent] [: blank:] spaces and tabs [: graph:] visible characters By expanding 33x126 [: lower:] lowercase letters [: upper:] uppercase letters [: print:] printable characters [: space:] blank characters, equivalent to [\ t\ r\ n\ v\ f] [: punct:] punctuation [: cntrl:] ASCII control code, including characters 0x31 and 127. all the contents of the article "what is grep regular expressions"? thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Examples characters expressions regular files file names equivalents ranges output content letters meanings symbols articles three strings numbers tags learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL Shulou Information MariaDB NVidia