import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\/(?<form>[^\\/]*)\\/\\d+\\/(?<rule>[^\\/]*)\\/\\w+\\/(?<mode>[^\\/]*)";
final String string = "http://linear-scope010.abc.com/LIVE/1002/hls/ae/TWAMCPH/98.m3u8\n\n"
+ "http://mmdai-linear-west-03.abc.com/linear-scope010.abc.com/LIVE/1008/hls/ae/Nat_HD/.swn71c39e69-9b76-45a0-a2da-005056b23b1dapple2apple/.rate_2737280/index_v_2737280_6.m3u8?nw=376521≺of=376521:twc_hls_live&mode=live&vdur=600&caid=NGC_LIVE&csid=stva_android_ph_live&vcid=369573a4-4f5b-3aa7-a42b-2eec0477efda&z5=79912&ads=VAST_LIVE&tagset_name=VAST&_fw_lpu=http://linear-scope010.abc.com/LIVE/1008/hl...";
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