2009年8月11日 星期二

正規表示式1 regular expressions


出處 http://osteele.com/tools/rework/

For more information about how to use regular expressions, including examples, additional documentation, and additional tools, see:
Regular-Expressions.info (online)
RegExLib (online)
Jeffrey Freidl's Mastering Regular Expressions (Amazon)

Quick Reference:
. any character except newline. If DOTALL, matches newline.
^ the start of the string. In multiline, matches start of each line.
$ the end of the string or just before the last newline. In multiline, matches before each newline.
\d,\w,\s digit, word, or whitespace, respectively
\D,\W,\S anything except digit, word, or whitespace
\. a period (and so on for \*, \(, etc.)
[ab] characters a or b
[a-c] a through c
[^ab] any character except a or b
expr* zero or more repetitions of expr
expr+ one or more repetitions of expr
expr? zero or one repetition of expr
*?,+?,?? ...same as above, but as little text as possible
expr{m} m copies of expr
expr{m,n} between m and n copies of the preceding expression
expr{m,n}? ...but as few as possible
a|b either a or b
(expr) same as expr, but captures the match for use in \1, etc.
(?:expr) doesn't capture the match
(?=expr) followed by expr
(?!expr) not followed by expr

沒有留言: