I have a dictionary file containing lines
ns*.abc.com
ns*.xyz.com
I want to match patterns such as ns15.abc.com, nsABC.abc.com with the dictionary file and return true.
E.g. ns15.abc.com is match while ns16.ABC.abc.com is not a match.
Thanks in advance
public class ValidateDemo {
public static void main(String[] args) {
List<String> input = new ArrayList<String>();
input.add("ns14.abc.com");
for (String str : input) {
if (str.matches("ns*.abc.com")) {
System.out.println("Match: " + str);
}
}
}
}
In each entry from the dictionary, replace asterisk by
"[^\.]*"and dot by"\."– there’s your pattern for each individual entry:Or you can also join all dictionary entries with “|” to have single pattern matching them all.