import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?=(?=(?'a'[\\s\\S]*))(?<!'b'<p\\b[^>][\\s\\S]color[\\s\\S]:[\\s\\S]black[^>][\\s\\S]>[\\s\\S]<span\\b[^>][\\s\\S]>[\\s\\S])(?<!<span\\b[^>][\\s\\S]color[\\s\\S]:[\\s\\S]black[^>][\\s\\S]>[\\s\\S])_(?=\\k'a'\\z)|(?<=(?=x^|(?<!&b))[\\s\\S]))<code\\s*style=\"background-color:\\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"
+ "<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