import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "views\\.decorators\\.cache\\.cache_(?:page|header)\\.([[:alnum:]]+)\\.(?:GET\\.)?([[:alnum:]]+)(?:\\.[[:alnum:]]+)?\\.en-us\\.UTC";
final String string = "views.decorators.cache.cache_header.APISetOne.596e986edcf211a323dbac38fe3654b8.en-us.UTC\n"
+ "views.decorators.cache.cache_page.APISetTwo.GET.1fc365e1f67d39935b199c133fada23b.ce596bddd33104b703521c71eb2e32c6.en-us.UTC";
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