import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\n"
+ " (?P<show>[a-zA-Z1-9\\.\\-]+[^\\.])\n"
+ " \\.[Ss]?(?P<season>\\d{1,2})[EeXx](?P<episode>\\d{1,2})\n"
+ " (\\.(?P<title>[a-zA-Z1-9\\.]+[^\\.]))?\n"
+ " \\.(?P<resolution>\\d{3,4}p)\n"
+ " \\.(?P<quality>[a-zA-Z\\-]{1,6})\n"
+ " \\.(?P<codec>[a-zA-Z0-9\\.]+\\d)\n"
+ " ([\\.\\-](?P<team>.+))?\n"
+ "$";
final String string = "Person.of.Interest.S05E13.720p.HDTV.X264-DIMENSION\n"
+ "The.Big.Bang.Theory.S09E21.720p.HDTV.X264-DIMENSION[ettv]\n"
+ "Homeland.S05E11.Our.Man.in.Damascus.720p.WEB-DL.DD5.1.H264-NTb[rarbg]\n"
+ "limitless.s01e01.pilot.720p.webrip.hevc.x265.rmteam\n"
+ "vikings.s04e01.a.good.treason.720p.web.dl.hevc.x265.rmteam\n"
+ "Brooklyn.Nine-Nine.S03E23.720p.WEBRip.x264\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.COMMENTS);
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