23 Dec 2006, 11:38am
電腦
by lachesis

leave a comment

[筆記]Regular Expression要跳脫的字元

每次忘記都要問google大神,還是做個筆記好了。

必須用反斜線跳脫的RE專用字元有:

. * + ? | ^ $ \ [ ] { } <> ( )

過濾某些ascii範圍可以這樣下:
$regPattern = “[\x00-\x40\\x5B-\x60\\x7B-\x7F\xA1\x40-\xA3\x43\xA3\xC0-\xA3\xFF]“;
//過濾特殊字元和全形和數字

Predefined Charactor Classes

. Any character (may or may not match line 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]

資料整理不錯的網頁:

http://en.wikipedia.org/wiki/Regular_expression

http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

*name

*e-mail

web site

leave a comment