title: Java regexp match pattern
body: <p>I need to check a pattern against some text (I have to check if my pattern is inside many texts).</p>
  
  <p>This is my example </p>
  
  <pre><code>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");
  </code></pre>
  
  <p>For my test, the pattern must match but using my regexp does not match.
  Must match :</p>
  
  <pre><code>" 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"
  </code></pre>
  
  <p>Must not match:</p>
  
  <pre><code>" -toto win bla bla"
  " pretoto win bla bla"
  </code></pre>
  
  <p>I try to do it using my regexp but it does not work.</p>
  
  <p>Can you point me what I'm doing wrong ?</p>