I wrote the following a java by using a regular expression to find a repeated String in the String s. Now I try to find the complexity of it, if any one know what is the complexity of it, please let me know.
String s = "ABCABCAAAABBBBCCAAABCGABCABC";
Pattern pattern = Pattern.compile("(?:([ABC])(?!\\1)([ABC])\\1\\2)+");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
System.out.print("FOUND");
}
+on that, meaning one or more. This could potentially search the whole string. However it requires only one to match, so the first match should suffice. So I think it will only scan through the string once or twice, depending, so time complexity roughly equal to the number of characters in the target strings.