import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=asad=).*?(?=(?:&|\\n))";
final String string = "https://teststore.com/products/mens-sandals-black?asad=253485_e1c6ae3ad&ol_color=13968\n"
+ "https://teststore.com/products/womens-sandals-tan-?asad=252485_c1c63c01d&variant=2770725251\n"
+ "https://teststore.com/products/mens-shoes-blue?asad=254325_c1c63c01d\n"
+ "https://teststore.com/collections/men/products/mens-sneakers?variant=310637539&asad=204207_e1c1756d5\n";
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