import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:.*|)NY TORRENT: [a-zA-Z&]+ \\w+ (.*-[a-zA-Z]+).*";
final String string = "NY TORRENT: Dance Single Croatia_Squad_-_Touch_Me-(ETR236)-WEB-2014-XDS 41.62MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1972)\n"
+ "NY TORRENT: Dance Single Croatia_Squad_-_Touch_Me-(ETR236)-WEB-2014-XDS 41.62MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1972)\n"
+ "NY TORRENT: R&B Album David_Guetta-Listen-2CD-2014-VOiCE 116.67MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1973)\n"
+ "NY TORRENT: Club Single DJ_EBO_-_Triple_Jump_98-Vinyl-1998-iDC 33.98MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1974)\n"
+ "(22:15:27) (@TTBot) NY TORRENT: Dance Single Audio_Hedz_and_Bones_-_Boom_Bang-(OMP_004)-WEB-2013-NRG 14.58MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1749)\n"
+ "(22:15:27) (@TTBot) NY TORRENT: Dance Single Bounce_Enforcerz_-_Good_Dawn-(RRBEG)-WEB-2014-NRG 16.12MB (http://tunetraxx.org/?p=torrents&pid=10&action=details&tid=1750)";
final String subst = "\\1";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
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