I want to apply the following regex to a string. It runs fine with Grant Skinners Regexr, it also runs fine on http://www.regexplanet.com/advanced/java/index.html (case-sensitive set) but Java just won't swallow it. It never hit's the while-loop. Here's my code:
public static void main(String args[]) {
final String testString =
"lorem upsadsad asda 12esadas test@test.com 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();
}
}