import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\<li\\>[^<]*?(Fandoms).*?\\<\\/li\\>";
final String string = "<p>by <a rel=\"author\" href=\"/users/Ellixerff/pseuds/Ellixerff\">Ellixerff</a></p>\n"
+ "<p>It's happened before, but this time is different. Can the consequences of bringing the one you love back, cost you ev fin story.</p>\n"
+ "<p>Words: 8003, Chapters: 7/7, Language: English</p>\n"
+ "<ul>\n"
+ " <li>Fandoms: <a full_pat class=\"tag\" href=\"https://archiveofourown.org/tags/Xena:%20Warrior%20Princess/works\">Xeni Princess</a></li>\n"
+ " <li>Rating: <a full_path=\"true\" class=\"tag\" href=\"https://archiveofourown.org/tags/Mature/works\">Mature</a></li>\n"
+ " <li>Warnings: <a full_f class=\"tag\" href=\"https://archiveofourown.org/tags/Choose\"> Chose Not To Use Archive Warnings</a></li>\n"
+ " <li>Categories: <a full_path=\"true\" class=\"tag\" href=\"https://archiveofourown.org/tags/F*s*F/works\">F/F</a></li>\n"
+ " <li>Characters: <a full_path=\"true\" href=\"https://archiveofourown.org/tags/Gabrielle%20(Xena)/works\">Gabrielle (Xena)</a></li>\n"
+ " <li><a fi class=\"tag\" href=\"https://archiveofourown.org/tags/Xena%20(Xena)/works\">Xena (Xena)</a></li>\n"
+ " <li>Relationships: <a full_path=\"true\" class=\"tag\" href=\"https://archiveofourown.org/tags/Gabrielle*s*Xena/works\">Gabrielle/Xena</a></li>\n"
+ "</ul>\n";
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
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