Construct | Matches |
---|---|
Characters | |
x | The characterx |
\\ | The backslash character |
\0n | The character with octal value0n(0<=n<=7) |
\0nn | The character with octal value0nn(0<=n<=7) |
\0mnn | The character with octal value0mnn(0<=m<=3, 0<=n<=7) |
\xhh | The character with hexadecimalvalue0xhh |
\uhhhh | The character with hexadecimalvalue0xhhhh |
\t | The tab character ('\ ') |
\n | The newline (line feed) character ('\ ') |
\r | The carriage-return character ('\ ') |
\f | The form-feed character ('\ ') |
\a | The alert (bell) character ('\') |
\e | The escape character ('\') |
\cx | The control character corresponding tox |
Character classes | |
[abc] | a,b, orc(simple class) |
[^abc] | Any character excepta,b, orc(negation) |
[a-zA-Z] | athroughzorAthroughZ, inclusive (range) |
[a-d[m-p]] | athroughd, ormthroughp:[a-dm-p](union) |
[a-z&&[def]] | d,e, orf(intersection) |
[a-z&&[^bc]] | athroughz, except forbandc:[ad-z](subtraction) |
[a-z&&[^m-p]] | athroughz, and notmthroughp:[a-lq-z](subtraction) |
Predefined character classes | |
. | Any character (may or may not matchline terminators) |
\d | A digit:[0-9] |
\D | A non-digit:[^0-9] |
\s | A whitespace character:[ \t\n\x0B\f\r] |
\S | A non-whitespace character:[^\s] |
\w | A word character:[a-zA-Z_0-9] |
\W | A non-word character:[^\w] |
POSIX character classes (US-ASCII only) | |
\p{Lower} | A lower-case alphabetic character:[a-z] |
\p{Upper} | An upper-case alphabetic character:[A-Z] |
\p{ASCII} | All ASCII:[\x00-\x7F] |
\p{Alpha} | An alphabetic character:[\p{Lower}\p{Upper}] |
\p{Digit} | A decimal digit:[0-9] |
\p{Alnum} | An alphanumeric character:[\p{Alpha}\p{Digit}] |
\p{Punct} | Punctuation: One of!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ |
\p{Graph} | A visible character:[\p{Alnum}\p{Punct}] |
\p{Print} | A printable character:[\p{Graph}] |
\p{Blank} | A space or a tab:[ \t] |
\p{Cntrl} | A control character:[\x00-\x1F\x7F] |
\p{XDigit} | A hexadecimal digit:[0-9a-fA-F] |
\p{Space} | A whitespace character:[ \t\n\x0B\f\r] |
Classes for Unicode blocks and categories | |
\p{InGreek} | A character in the Greekblock (simpleblock) |
\p{Lu} | An uppercase letter (simplecategory) |
\p{Sc} | A currency symbol |
\P{InGreek} | Any character except one in the Greek block (negation) |
[\p{L}&&[^\p{Lu}]] | Any letter except an uppercase letter (subtraction) |
Boundary matchers | |
^ | The beginning of a line |
$ | The end of a line |
\b | A word boundary |
\B | A non-word boundary |
\A | The beginning of the input |
\G | The end of the previous match |
\Z | The end of the input but for the finalterminator, ifany |
\z | The end of the input |
Greedy quantifiers | |
X? | X, once or not at all |
X* | X, zero or more times |
X+ | X, one or more times |
X{n} | X, exactlyntimes |
X{n,} | X, at leastntimes |
X{n,m} | X, at leastnbut not more thanmtimes |
Reluctant quantifiers | |
X?? | X, once or not at all |
X*? | X, zero or more times |
X+? | X, one or more times |
X{n}? | X, exactlyntimes |
X{n,}? | X, at leastntimes |
X{n,m}? | X, at leastnbut not more thanmtimes |
Possessive quantifiers | |
X?+ | X, once or not at all |
X*+ | X, zero or more times |
X++ | X, one or more times |
X{n}+ | X, exactlyntimes |
X{n,}+ | X, at leastntimes |
X{n,m}+ | X, at leastnbut not more thanmtimes |
Logical operators | |
XY | Xfollowed byY |
X|Y | EitherXorY |
(X) | X, as acapturing group |
Back references | |
\n | Whatever thenthcapturing groupmatched |
Quotation | |
\ | Nothing, but quotes the following character |
\Q | Nothing, but quotes all characters until\E |
\E | Nothing, but ends quoting started by\Q |
Special constructs (non-capturing) | |
(?:X) | X, as a non-capturing group |
(?idmsux-idmsux) | Nothing, but turns match flags on - off |
(?idmsux-idmsux:X) | X, as anon-capturing groupwith the given flags on - off |
(?=X) | X, via zero-width positive lookahead |
(?!X) | X, via zero-width negative lookahead |
(?<=X) | X, via zero-width positive lookbehind |
(?<!X) | X, via zero-width negative lookbehind |
(?>X) | X, as an independent, non-capturing group |
Eclipse中查找替换所使用的正则表达式的定义
最新推荐文章于 2021-01-06 13:15:53 发布