import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:color:\\s*|pid=\\d*)#(*SKIP)(*F)|#(\\w+)";
final String string = "<span style=\"font-weight: bold;\">test1<span style=\"color: #FFA500;\">test2</span>test3</span>#hello#how#are#you\n"
+ "<span style=\"font-weight: bold;\">test1<span style=\"color: #FFA500;\">test2</span>test3</span>#lalala #hello\n"
+ "<div class=\"post_body\" id=\"pid_58705\">\n"
+ "<blockquote><cite><span> (Hoy 02:42)</span>Moroha escribió: <a class=\"quick_jump\" href=\"http://test.com/Thread-hello?pid=58672#pid58672\" rel=\"nofollow\"> </a></cite>testing</blockquote></div>\n"
+ "pid=97589735935795358672#foobar";
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