title: Java: Finding the number of word matches in a given string
body: <p>I am trying to find the number of <strong>word matches</strong> for a given string and keyword combination, like this:</p>
  
  <pre><code>public int matches(String keyword, String text){
   // ...
  }
  </code></pre>
  
  <p><strong>Example:</strong></p>
  
  <p>Given the following calls:</p>
  
  <pre><code>System.out.println(matches("t", "Today is really great, isn't that GREAT?"));
  System.out.println(matches("great", "Today is really great, isn't that GREAT?"));
  </code></pre>
  
  <p>The result should be:</p>
  
  <pre><code>0
  2
  </code></pre>
  
  <p>So far I found this: <a href="https://stackoverflow.com/questions/2765482/find-a-complete-word-in-a-string-java">Find a complete word in a string java</a></p>
  
  <p>This only returns <strong>if</strong> the given keyword exists but not <strong>how many</strong> occurrences. Also, I am not sure if it ignores <strong>case sensitivity</strong> (which is important for me).</p>
  
  <p>Remember that substrings should be ignored! I only want <strong>full words</strong> to be found.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I forgot to mention that I also want keywords that are separated via whitespace to match.</p>
  
  <p>E.g.</p>
  
  <pre><code>matches("today is", "Today is really great, isn't that GREAT?")
  </code></pre>
  
  <p>should return 1</p>