import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\s*<div class=\"new\">.*?href=\"((?:.*?)channel=(.*?))\".*?src=\"(.*?)\".*?</a>\\s*</div>";
final String string = "<div class=\"new\"> <a class=\"block\" target=\"_blank\" href=\"http://somesite:8080/hls/mango1.m3u8?token=34523sedfsdfsdf&e=123456789&channel=mango1\" data-toggle=\"modal\" data-target=\"#mango1\">\n"
+ "<div class=\"image-container\"> <img src=\"images/mango1.png\" class=\"img-responsive\" > </div>\n"
+ "</a> </div>\n\n"
+ " <div class=\"new\"> <a class=\"block\" target=\"_blank\" href=\"http://somesite:8080/hls/mango2.m3u8?token=sfaesfraesgh452342&e=987654321&channel=mango2\" data-toggle=\"modal\" data-target=\"#mango2\">\n"
+ "<div class=\"image-container\"> <img src=\"images/mango2.png\" class=\"img-responsive\" > </div>\n"
+ "</a> </div>";
final String subst = "HREF: \\1\\nCHANNEL: \\2\\nSRC: \\3\\n\\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
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