Suppose I have a list of regular expressions that I want my input string to match with like :
List<String> regexList = new ArrayList<>();
regexList.add("(.*)apple"); // regex1 - anything ending with apple
regexList.add("smart(.*)"); // regex2 - anything starting with smart
boolean isMatching(input) {
for (String regex : regexList) {
if (input.matches(regex)) return true;
}
return false;
}
OR
String regexCombined = "((.*)apple)|(smart(.*))";
boolean isMatching(input) {
return input.matches(regexCombined);
}
Now if have suppose N regex to handle. What will be the time complexities of both the approaches?