Matches zero or more repetitions of previous character string or RE.
Example: grep '^12*' testre
12
1122
11222
1222
1111111111
2: .
Matches any one character including space but not new line.
grep '^12.' testre1222
3: ^
Match the beginning of line.
4: $
Match the end of line.
5: Brackets -- [...] -- enclose a set of characters to match in a single RE.
"[xyz]" matches any one of the characters x, y, or z.
"[c-n]" matches any one of the characters in the range c to n.
"[B-Pk-y]" matches any one of the characters in the ranges B to P and k to y.
"[a-z0-9]" matches any single lowercase letter or any digit.
"[^b-d]" matches any character except those in the range b to d. This is an instance of ^ negating or inverting the meaning of the following RE (taking on a role similar to ! in a different context).
Combined sequences of bracketed characters match common word patterns. "[Yy][Ee][Ss]" matches yes, Yes, YES, yEs, and so forth. "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" matches any Social Security number.
6: The backslash -- \ -- escapes a special character, which means that character gets interpreted literally (and is therefore no longer special).
A "\$" reverts back to its literal meaning of "$", rather than its RE meaning of end-of-line. Likewise a "\\" has the literal meaning of "\".
7: ?
Match zero or one of previous RE.
8: +
Match one or more of previous RE. Similar to *, but at least one occurrence.
9: Escaped "curly brackets" -- \{ \} -- indicate the number of occurrences of a preceding RE to match.
It is necessary to escape the curly brackets since they have only their literal character meaning otherwise. This usage is technically not part of the basic RE set.
"[0-9]\{5\}" matches exactly five digits (characters in the range of 0 to 9).
10: Parentheses -- ( ) -- enclose a group of REs. They are useful with the following "|" operator and in substring extraction using expr.
11: The -- | -- "or" RE operator matches any of a set of alternate characters.
12: POSIX Character Classes. [:class:]
This is an alternate method of specifying a range of characters to match.
[:alnum:] matches alphabetic or numeric characters. This is equivalent to A-Za-z0-9.
[:alpha:] matches alphabetic characters. This is equivalent to A-Za-z.
[:blank:] matches a space or a tab.
[:cntrl:] matches control characters.
[:digit:] matches (decimal) digits. This is equivalent to 0-9.
[:graph:] (graphic printable characters). Matches characters in the range of ASCII 33 - 126. This is the same as [:print:], below, but excluding the space character.
[:lower:] matches lowercase alphabetic characters. This is equivalent to a-z.
[:print:] (printable characters). Matches characters in the range of ASCII 32 - 126. This is the same as [:graph:], above, but adding the space character.
[:space:] matches whitespace characters (space and horizontal tab).
[:upper:] matches uppercase alphabetic characters. This is equivalent to A-Z.
[:xdigit:] matches hexadecimal digits. This is equivalent to 0-9A-Fa-f.
No comments:
Post a Comment