title: Multiple regex patterns to find. Java
body: <p>I need to calculate separately number of words and sentences in string and i have these two methods which works fine:</p>
  
  <pre><code>    Pattern pattern = Pattern.compile("\\w+\\s|\\w+\\,|\\w+\\.|\\w+\\?|\\w+\\!*$");
      Matcher match1 = pattern.matcher(s);
      while(match1.find()) {
          counterWords++;
      }   
  </code></pre>
  
  <p>and for sentences:</p>
  
  <pre><code>    Pattern pattern = Pattern.compile("[^?!.][?!.]");
      Matcher match2 = pattern.matcher(s);
      while(match2.find()) {
          counterSentences++;
      }   
  </code></pre>
  
  <p>The next task is to calculate it again, but in one loop, so I tried:</p>
  
  <pre><code>while(match1.find() || match2.find()){
      if(match1.find()){
          counterWords++;
      }
      if(match2.find()){
          counterSentences++;
      }
  </code></pre>
  
  <p>However, the method is not working properly, it counts sentences correctly, but word counter is 2 times less that actual number of words. Most probably I don't understand completely how matcher.find() works, could somebody explain what I am doing wrong?
  Thank you.</p>