Java示例计数单词组2


Java示例计数单词组2

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
   public static void main(String[] args) {
      String s1 = "SairamkrishnaxxxxxMammahe";
      Pattern pattern = Pattern.compile("Sairamkrishna");
      Matcher  matcher = pattern.matcher(s1);
      int count = 0;

      while (matcher.find())count++;
      System.out.println(count);
   }
}