Java正则表达式中的POSIX字符等价物

Ste*_*han 5 java regex posix-ere character-properties

我想在Java中使用这样的正则表达式:[[=a=][=e=][=i=]].

但Java不支持POSIX类[=a=], [=e=] etc.

我怎样才能做到这一点?更准确地说,有没有办法不使用US-ASCII?

Joh*_*erg 12

Java确实支持posix字符类.语法不同,例如:

\p{Lower}
\p{Upper}
\p{ASCII}
\p{Alpha}
\p{Digit}
\p{Alnum}
\p{Punct}
\p{Graph}
\p{Print}
\p{Blank}
\p{Cntrl}
\p{XDigit}
\p{Space}
Run Code Online (Sandbox Code Playgroud)


Ahm*_*gle 6

引自http://download.oracle.com/javase/1.6.0/docs/api/java/util/regex/Pattern.html

POSIX字符类(仅限US-ASCII)

\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}\x20]
\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]
Run Code Online (Sandbox Code Playgroud)