import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(cm_mmc).*(-_-).*(-_-).*(-_-)";
final String string = "http://m.macys.com/shop/makeup-and-perfume/cologne-for-men?id=30088&edge=hybrid&cm_sp=us_hdr-_-beauty30088_cologne-&-grooming_COL3&cm_mmc=Carat_Social-_-facebook-_-jun2_frag_dad_gwp_fb_dr_roas_u6050067_11707_1420538-_-06062016_06162016&dclid=COjhz-annc0CFQ8FgQod-ycCPA";
final Pattern pattern = Pattern.compile(regex);
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