title: How to extract number of occurances of a reponse string in Jmeter and fail the test if the occurances does not match a number?
body: <p>I am trying to count the number of occurrences of a response in Jmeter and if the count is not equal to 4, the test should fail. </p>
  
  <p>How can i do that?</p>
  
  <p>I used this in beanshell assertion:</p>
  
  <pre><code>Import org.apache.commons.lang3.StringUtils;
  
  int matches = StringUtils.countMatches(new String(data), "itemname"); 
  vars.put("ItemNameVar_matchNr", String.valueOf(matches));
  assert matches == 5;
  </code></pre>
  
  <p>It. is not working. It shows error: </p>
  
  <blockquote>
    <p>Typed variable declaration : Undefined argument: data</p>
  </blockquote>