我想將以下正則表達式應用於字符串。它與Grant Skinners Regexr一起運行良好,它在http://www.regexplanet.com/advanced/java/index.html(區分大小寫的集合)上運行良好,但Java不會吞下它。它從來沒有打到while循環。這裏是我的代碼:正則表達式不起作用
public static void main(String args[]) {
final String testString =
"lorem upsadsad asda 12esadas [email protected] asdlawaljkads test[at]test" +
"[dot]com test jasdsa meter";
final Pattern ptr =
Pattern.compile(
"^[A-Z0-9\\._%+-]+(@|\\s*\\[\\s*at\\s*\\]\\s*)[A-Z0-9\\.-]+" +
"(\\.|\\s*\\[\\s*dot\\s*\\]\\s*)[a-z]{2,6}$",
Pattern.CASE_INSENSITIVE);
try {
final Matcher mat = ptr.matcher(testString);
while (mat.find()) {
final String group1 = mat.group(1);
System.out.println(group1);
final String group2 = mat.group(2);
System.out.println(group2);
final String group3 = mat.group(3);
System.out.println(group3);
}
} catch (final Exception e) {
e.printStackTrace();
}
}
你正在做的是什麼正則表達式/代碼?此外,我只是在regexplanet中測試了你的正則表達式,它不匹配你的字符串或者找到任何子字符串。 – Pshemo
你能解釋一下正在做什麼正則表達式? – 2013-11-01 17:50:47
當我使用正則表達式 – user2202911