2013-10-22 59 views
-10

我有一些代碼:???什麼字符((:(:(?:意味着模式匹配

import java.util.regex.Matcher; 
import java.util.regex.Pattern; 
import org.apache.commons.lang.StringUtils; 

private boolean validateEmail(...) 

Pattern p = Pattern.compile("^((?:(?:(?:[a-zA-Z0-9][\\.\\-\\+_]?)*)[a-zA-Z0-9])+)\\@((?:(?:(?:[a-zA-Z0-9][\\.\\-_]?){0,62})[a-zA-Z0-9])+)\\.([a-zA-Z0-9]{2,6})$"); 

Matcher m = p.matcher(fieldValue); 
boolean matches = m.matches(); 

if (!matches) {  
// show not valid msg... 
} 
return matches; 
} 

什麼^((?:(?:(?:((?:(?:(?:在這種模式意味着 的^字符意味着什麼?當你想組的表達否定(所有這些都不),但是其它字符?

+4

[文檔](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)告訴你它們是什麼意思? –

+0

這裏有幾個Java正則表達式教程讓你開始:http://www.vogella.com/articles/JavaRegularExpressions/article.html http://docs.oracle.com/javase/1.4.2/docs/api /java/util/regex/Pattern.html – codeMan

+10

他們是微笑 - 這就是正則表達式如何表達對你的同情。 –

回答

2

(?:...)表示非捕獲組。?:被使用,但要避免將其返回作爲所述串的匹配/捕獲部。

^並不意味着當它位於正方形夾克之外時的否定。它意味着從字符串的開始處進行匹配。