Q:

How do I figure out which regular expression matches my string?

I have 10 regular expressions and 1 one string which may or may not match exactly one of those 10 regular expressions. Does anyone know of a simple way to figure out which regular expression, if any, matches my string? I know that I can simply test each one against the string but I'd like to know if there's a library out there that I can input the regular expressions and the string and it'll tell me if any of my regular expressions match. I need to know which regular expression is matched because the resulting business logic is different for each regular expression.

A:

Here's the API you're looking for. Just invoke it for each of the 10 expressions!
public boolean testMatch(String data, String regEx) {
    return data.matches(regEx);
}

Let's make it more generic.
public String testMatch(String data, String... regExs) {
    for(String regEx : regExs) {
        if(data.matches(regEx)) {
            return regEx;
        }
    }

    return null;
}

