import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
String regex = "([a-zA-Z'-]*[ ]*)*";
Pattern p = Pattern.compile(regex);
String input = "Adarsh has been testing this issue for a very long time now!#!";
Matcher m = p.matcher(input);
System.out.println("Called");
if(m.matches())
System.out.println("Matched");
else
System.out.println("Not Matched");
if(input.matches(regex))
System.out.println("Matched");
else
System.out.println("Not Matched");
}
}
I use the above code in a form field and validation is done in the java class.(The above example is just an equivalent for the actual one) The maximum length for that textbox set is 80 chars. However i face a strange issue. The system validates a correct textbox entry. However when a wrong value is entered for strings of length greater than approximately 50. The
Pattern.compile()
takes a long time and also the matcher.match() does not execute . I also tried the default match() in String. But still have the same issue. Is there any problem with the regex library.? Or am i missing something? Note : CPU Usage has gone to 100%