import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?<modifiers>\\/(?<crop>\\d+x\\d+:\\d+x\\d+)?\\/?(?<resize>(?<flipx>\\-)?(?<width>\\d+)x(?<flipy>\\-)?(?<height>\\d+))?\\/?(?<filters>filters\\:([^,\\/]+,)*(?:format\\((?<format>\\w+)\\))?[^\\/]*\\/?)?)?(?<id>\\/f\\/.+)$\n";
final String string = "/100x100:450x350/200x200/filters:grayscale()/f/39898/1000x600/d962430746/demo-image-human.jpeg\n"
+ "/600x130/f/39898/2250x1500/c15735a73c/demo-image-human.jpeg\n"
+ "/-230x230/filters:rotate(90)/f/39898/1000x600/d962430746/demo-image-human.jpeg\n"
+ "/f/39898/3310x2192/e4ec08624e/demo-image.jpeg\n"
+ "/200x0/filters:format(png)/f/39898/3310x2192/e4ec08624e/demo-image.jpeg\n"
+ "/f/39898/3310x2192/e4ec08624e/demo-image.jpeg\n"
+ "/200x0/filters:something(),format(png)/f/39898/3310x2192/e4ec08624e/demo-image.jpeg\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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