| Character Class: Single Characters and Digits | |
| . | Matches any character except a newline |
| [a–z0–9] | Matches any single character in set |
| [^a–z0–9] | Matches any single character not in set |
| \d | Matches one digit |
| \D | Matches a nondigit, same as [^0–9] |
| \w | Matches an alphanumeric (word) character |
| \W | Matches a nonalphanumeric (nonword) character |
| Character Class: Whitespace Characters | |
| \s | Matches a whitespace character, such as spaces, tabs, and newlines |
| \S | Matches nonwhitespace character |
| \n | Matches a newline |
| \r | Matches a return |
| \t | Matches a tab |
| \f | Matches a form feed |
| \b | Matches a backspace |
| \0 | Matches a null character |
| Character Class: Anchored Characters | |
| \b | Matches a word boundary (when not inside [ ]) |
| \B | Matches a nonword boundary |
| ^ | Matches to beginning of line |
| $ | Matches to end of line |
| \A | Matches the beginning of the string only |
| \Z | Matches the end of the string or line |
| \z | Matches the end of string only |
| \G | Matches where previous m//g left off |
| Character Class: Repeated Characters | |
| x? | Matches 0 or 1 x |
| x* | Matches 0 or more occurrences of x |
| x+ | Matches 1 or more occurrences of x |
| (xyz)+ | Matches 1 or more patterns of xyz |
| x{m,n} | Matches at least m occurrences of x and no more than n occurrences of x |
| Character Class: Alternative Characters | |
| was|were|will | Matches one of was, were, or will |
| Character Class: Remembered Characters | |
| (string) | Used for backreferencing |
| \1 or $1 | Matches first set of parentheses |
| \2 or $2 | Matches second set of parentheses |
| \3 or $3 | Matches third set of parentheses |
| Character Class: Miscellaneous Characters | |
| \12 | Matches that octal value, up to \377 |
| \x811 | Matches that hex value |
| \cX | Matches that control character; e.g., \cC is |
| \e | Matches the ASCII ESC character, not backslash |
| \E | Marks the end of changing case with \U, \L, or \Q |
| \l | Lowercase the next character only |
| \L | Lowercase characters until the end of the string or until \E |
| \N | Matches that named character; e.g., \N{greek:Beta} |
| \p{PROPERTY} | Matches any character with the named property; e.g., \p{IsAlpha}/ |
| \P{PROPERTY} | Matches any character without the named property |
| \Q | Quote metacharacters until \E |
| \u | Titlecase next character only |
| \U | Uppercase until \E |
| \x{NUMBER} | Matches Unicode NUMBER given in hexadecimal |
| \X | Matches Unicode "combining character sequence" string |
| \[ | Matches that metacharacter |
| \\ | Matches a backslash |
2009年7月1日星期三
为了启动的纪念 perl 正则
有时想不起来,记一下:(源自perl by example edition 4)
订阅:
博文评论 (Atom)
没有评论:
发表评论