import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[^\\S\\r\\n]+artist:[^\\S\\r\\n]*(.*)";
final String string = "mp3 @ 0x75b225b8]Estimating duration from bitrate, this may be inaccurate\n"
+ "[lavf] stream 0: audio (mp3), -aid 0\n"
+ "[lavf] stream 1: video (mjpeg), -vid 0, \n\n"
+ "Clip info:\n"
+ " Release date: Songspk.LINK\n"
+ " album_artist: Various Artists\n"
+ " album: Kapoor & Sons (Since 1921)\n"
+ " artist: Tanishk Bagchi, Arijit Singh & Asees Kaur\n\n"
+ " composer: Amaal Mallik | Songspk.LINK\n"
+ " disc: 1/1\n"
+ " encoded_by: Lame\n"
+ " genre: Bollywood Music\n"
+ " title: Bolna - Songspk.LINK\n"
+ " track: 1/1\n"
+ " EpisodeID: Songspk.LINK\n"
+ " copyright: Songspk.LINK\n"
+ " TOPE: Amaal Mallik | Songspk.LINK\n"
+ " TIT1: Songspk.LINK\n"
+ " TIT3: Songspk.LINK";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
if (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