Basic Regular Expression
1. Regular Expressions regular expressions are the method for processing strings and are processed in the unit of action. 2. Basic Regular Expression characters use the following special characters
^ String the grep '^ W' test file whose names start with w. string $ the grep 'day whose names end with string $ 'test' row whose names end with day. match any character grep-n' go. d' test finds good goad and other \ escape characters, escape special characters grep t \ 'his test * repeated 0 or multiple times grep 'go * d' test find good [list] Find the selected character [n1-n2] Find the selected the character range is grep '[0-9]' filename. Find the [a-z] containing numbers that contain all lowercase letters. [^ list] does not include the selected characters \ {n, m \} matches n to m times before the character \ {n \} appears n words, \ {n, \} appears n times or more3. The effect of a language family on regular expressions is different in the encoding data of different languages. For example, when the English case code is LANG = C, 0 1 2 3... a B C... Z a B c... when z LANG = zh_CN, 0 1 2 3 .... a A B B c C... z Z all when we take the [A-Z], LANG = C to take out the capital A-Z and LANG = zh_CN.gb2312 will take out B-z also. To avoid this problem, regular expressions are compatible with POSIX standards.
[: Digit:] Only the digits 0 to 9 matches the number [: alnum:] Any alphanumeric character 0 to 9 or a to Z or a to z. letters and numbers [: alpha:] Any alpha character A to Z or a to z. letter A-Z, a-z [: blank:] Space and TAB characters only. match space and tag [: xdigit:] Hexadecimal notation 0-9, A-F, a-f. hexadecimal number [: punct:] Punctuation symbols ., "'? ! ;: # $ % & () * +-/<> = @ [] \ ^ _ {} | ~ Punctuation [: print:] Any printable character. printable character [: space:] Any whitespace characters (space, tab, NL, FF, VT, CR ). using system abbreviate as \ s. any blank character [: graph:] Exclude whitespace (SPACE, TAB ). using system abbreviate as \ W. other buttons except space and tag [: upper:] Any alpha character A to Z. uppercase [: lower:] Any alpha character a to z. lowercase [: cntrl:] control Characters nl cr lf tab vt ff nul soh stx ext eot enq ack so si dle DC1 DC2 DC3 DC4 nak syn etb can em sub esc IS1 IS2 IS3 IS4 DEL. represents the control key on the keyboardIt is usually used with [], for example:
Grep '[[: digit:] 'test find the number grep' [[: alpha:] 'test find the letter
Address: http://blog.csdn.net/yonggang7/article/details/39118991