1. Regular Expression
A regular expression is a string processing method, which is 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 more
3. Influence of the language family on Regular Expressions
The encoding data of different languages is different. For example, when the English case code is lang = C, 0 1 2 3... a B C... z a B C... when zlang = zh_cn, 0 1 2 3 .... a a B C... 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. 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 keyboard
It 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
Basic Regular Expression