Regular Expressions Reguler expression , REGEXP
Basic REGEXP: base Regular Expression
Extended REGEXP: extending regular Expressions
1.grep [options] mode [files] commands for filtering text using the basic regular expression pattern
-I ignores case
--color plus Color
-V Reverse lookup
-O displays only strings that are matched by the pattern
- e support for extended regular expressions
-A N: shows not only the matches but also the n rows below the line
-B N: Shows not only the matches but also the n rows above the line
-C N: Displays not only matches but also rows above and below the line of n
Pattern rules
. match any single character
[] matches any single character within the specified range
[^] matches any single character outside the specified range
[: Space:]: white space character
[:p Unot:]: punctuation
[: Lower:]: lowercase letters
[: Upper:]: size Letter
[: Alpha:]: uppercase and lowercase letters
[:d igit:]: number
[: Alnum:]: numbers and uppercase and lowercase letters
Two when used [[]]
Number of Matches
*: matches its preceding character any time
\? : matches the preceding character 1 or 0 times
\{m,n\} matches the preceding characters at least m times up to n times
By default in greedy mode, match as many characters as possible
Position lock
^ Rivet Header, must start with its trailing character
$ Rivet Line End
^$ Blank Line
\<: Any character following it must appear as a word header or can be used \b
\>: Any character in front of it must appear as a trailing word or can be used \b
Group
\(\)
\1 referencing the first group
\2 referencing a second group
...
Extending regular Expressions
GREP-E = Egrep to use an extended regular expression
Character Matching:
. usage is the same as the basic regular
[]
[^]
Number of Matches
*:
?:
+: match the characters in front of it at least 1 times
{M,n} The usage is the same as the basic regular, but does not add \
Position Lock: Usage is the same as the basic
^
$
\<
\>
Group:
(): Group
\1 \2 \3 ...
Or
| : OR
Fgrep: Fast Search does not support regular expressions
This article is from the "Mr.zhu-Technology Exchange" blog, please be sure to keep this source http://bjishu.blog.51cto.com/7481301/1699663
Linux Regular expressions