I need to check a pattern against some text (I have to check if my pattern is inside many texts).
This is my example
String pattern = "^[a-zA-Z ]*toto win(\\W)*[a-zA-Z ]*$";
if("toto win because of".matches(pattern))
System.out.println("we have a winner");
else
System.out.println("we DON'T have a winner");
For my test, the pattern must match but using my regexp does not match.
Must match :
" toto win bla bla"
"toto win because of"
"toto win. bla bla"
"here. toto win. bla bla"
"here? toto win. bla bla"
"here %dfddfd . toto win. bla bla"
Must not match:
" -toto win bla bla"
" pretoto win bla bla"
I try to do it using my regexp but it does not work.
Can you point me what I’m doing wrong ?
This would work
Explanation
UPDATE 1
UPDATE 2
UPDATE 3
Explanation
RegEx need to escaped for using within code