import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:<(?:p|li)\\b[^>]*?color\\s*:\\s*(?:(black))[^>]*?>(?(1)(?:\\s*<span\\b[^>]*?>)?)|<span\\b[^>]*?color\\s*:\\s*black[^>]*?>)(?s)\\s*<code\\b(?:\".*?\"|'.*?'|[^>]*?)+>(*SKIP)(*FAIL)|<code\\b[^>]*?style[^>]*?background-color\\s*:\\s*transparent[^>]*?>";
final String string = "<html>\n"
+ "<p style=\"font-family: "verdana"; font-size: 18px; color: black; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: cyan;\"><span style=\"font-size: 13.5pt; font-family: "Verdana","sans-serif";\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span></p>\n"
+ "<li style=\"font-family: "verdana"; font-size: 18px; color: black; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: cyan;\"><span style=\"font-size: 13.5pt; font-family: "Verdana","sans-serif";\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span></li>\n"
+ "<span><span style=\"font-size: 13.5pt; font-family: "Verdana","sans-serif"; background-color: cyan;\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span>\n\n"
+ "<code style=\"background-color: transparent;\">\n\n"
+ "<p style=\"font-family: "verdana"; font-size: 18px; color: cyan; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: cyan;\"><span style=\"color: black; font-size: 13.5pt; font-family: "Verdana","sans-serif";\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span></p>\n"
+ "<span><span style=\"font-size: 13.5pt; font-family: "Verdana","sans-serif"; background-color: cyan;\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span>\n"
+ "<p style=\"font-family: "verdana"; font-size: 18px; color: cyan; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: navy;\"><span style=\"font-size: 13.5pt; font-family: "Verdana","sans-serif";\"><code style=\"background-color: transparent;\"><b>some text here</b></code></span></p>\n"
+ "</html>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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