vendredi 12 janvier 2018

Java regex pattern program dont finish during calling of method String.matches

I have the following regullar expression which matches any characters at the beginning ending with text in parenthesis "Hi (Stackoverflow)". When I enter this text to be matched the program does not finish with result. It is still running without finishing.

String pattern = "^[a-zA-Z]+([\\s]*[\\w]*)*\\([\\w]+\\)"
String text = "Asdadasdasd sadsdsad sdasd (s)"
String text2 = "Asdadasdasd sadsdsad sdasd (s) sdsd"

System.out.println(text.matches(pattern)) - it works
System.out.println(text2.matches(pattern)) - never ending story

What is wrong?

Aucun commentaire:

Enregistrer un commentaire