Patterns in Java Programming

Hello All, I am working on java project and I have a set of string and I am trying to use matches. My set of string, named patterns now has [title@*, text@*, specification*/specificationText] and I need to be able to convert it to [title@(.*), text@(.*), specification(.*)/specificationText] so that something like specification1/specificationText or anything else in place of 1 gets matched.

My string: String abc = "specification1/specificationText";

Can anyone suggest me, how to go about doing this?

The code that I have written on interviewbit online compiler.

private static Boolean isMatch(String abc, Set<String> patterns) {

    for (String pattern : patterns) {

        Pattern r = Pattern.compile(pattern);

        if (r.matcher(abc).matches()) {

            return Boolean.TRUE;
        }
    }

    return Boolean.FALSE;
}

Right now r takes the value, specification*/specification which is being compared with specification1/specification . So FALSE is being returned.

If you just need to replace * by (.*), maybe this is enough ?

Pattern r = Pattern.compile(pattern.replace("*", "(.*)"));

Or because you don’t need the capturing group :

Pattern r = Pattern.compile(pattern.replace("*", ".*"));