import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*mod_(\\S+?)(-part-\\d+)?\\.(csv|json)";
final String string = "cid:d09004b7478a4f338bf647519edf71a3/tag:1595602064/aid:095438ff38da41e4444059fdbd9af9fd/pid:64756d6d792c484f555345424152415448454f4e2c31302e3136302e332e3232342c323032302d30372d32375432325f35385f31315a2e786d6ce3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/mod_dirlist-part-000001.json.gz";
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