import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<\\w+.*?([\\w-]+=[\"']*\\s*(?:\\w+\\s*)*[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\s*(?:['\"]?(?:\\w+\\s*)*['\"]?)?[\"']*).*?>";
final String string = "<br data-a1=\"nope\" attr=\" jepp@get.me \" data-a2=\"nope\">\n"
+ "<br data-a1=\"nope\" attr=' jepp@get.me ' data-a2=\"nope\">\n"
+ "<br data-a1=\"nope\" attr=jepp@get.me data-a2=\"nope\">\n"
+ "<br data-a1=\"nope\" attr=\" jepp@get.me \" data-a2=\"nope\"/>\n"
+ "<br data-a1=\"nope\" attr=\" jepp@get.me \" data-a2=\"nope\" />\n"
+ "<tag data-a1=\"nope\" attr=\" jepp@get.me \" data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=' jepp@get.me ' data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=jepp@get.me data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=\" additional text jepp@get.me 'additional text'\" data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=\" additional text jepp@get.me additional text\" data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=' additional text jepp@get.me \"additional text\"' data-a2=\"nope\">text</tag>\n"
+ "<tag data-a1=\"nope\" attr=\" jepp@get.me jeppagain@get.me \" data-a2=\"nope\">text</tag>\n"
+ "abc dont@get.me 123 <input value=\"please@get.me\">xyz\n"
+ "abc dont@get.me 123 <tag1 att1=\"val1\" email1=\"please@get.me\">xyz\n"
+ "abc dont@get.me 123 <tag2 att1=\"val1\" email2=\"please@get.me\" att1=\"val1\">xyz\n"
+ "<tag2 att1=\"val1\" email3='please@get.me' att1=\"val1\">xyz\n"
+ "<tag2 att1=\"val1\" email4=please@get.me att1=\"val1\">xyz\n"
+ "<tag2 att1=\"val1\" email5=\" please@get.me \" att1=\"val1\">xyz\n"
+ "<tag2 att1=\"val1\" email6=' please@get.me ' att1=\"val1\">xyz\n"
+ "<tag data-yeah-also-valid-attr-name=\"please@get.me\">xyz\n"
+ "<tag data-yeah-attr=\"please@get.me\">\n"
+ "<tag data-yeah-attr='please@get.me'>\n"
+ "<tag data-yeah-attr=please@get.me>\n"
+ "<tag data-yeah-attr=\"'please@get.me'\">\n"
+ "<tag data-yeah-attr='\"please@get.me\"'>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html