import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\b([\\w\\-+()' .,]+(?:\\[[\\w\\-\\/+()' .,]*\\][\\w\\-+()' .,]*)*\\.[A-Za-z0-9]{2,4})\\b";
final String string = "Subject-KrzpfTest [02/30] - \"\"KrzpfTest.part.nzb\"\" yEnc\n"
+ "[PRiVATE]-[WtFnZb]-[Supertje-_S03E11-12_-blabla_+_blabla_WEBDL-480p.mkv]-[4/12] - \"\" yEnc 9786 (1/1366)\n"
+ "[N3wZ] MAlXD245333\\\\::[PRiVATE]-[WtFnZb]-[Show.S04E04.720p.AMZN.WEBRip.x264-GalaxyTV.mkv]-[1/2] - \"\" yEnc 293197257 (1/573)\n"
+ "Singer - A Album (2005) - [04/25] - 02 Sweetest Somebody (I Know).flac\n"
+ "[PRiVATE]-[WtFnZb]-[00000.clpi]-[1/46] - \"\" yEnc 788 (1/1)\n"
+ "[PRiVATE]-[WtFnZb]-[/More.Bla.S02E01.1080p.WEB.h264-EDITH[eztv.re].mkv] yEnc 2990558544 (1/4173)\n\n";
final Pattern pattern = Pattern.compile(regex);
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