RegexUtil.java 988 B

12345678910111213141516171819202122232425262728293031
  1. package com.huimv.env.common.utils;
  2. import org.springframework.stereotype.Component;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5. /**
  6. * @Project : huimv.shiwan
  7. * @Package : com.huimv.biosafety.uface.controller
  8. * @Description : TODO
  9. * @Version : 1.0
  10. * @Author : ZhuoNing
  11. * @Create : 2020-12-25
  12. **/
  13. @Component
  14. public class RegexUtil {
  15. //计算+出现的次数
  16. public int countPlus(String str) {//创建countSpace方法用于统计文本的空格个数
  17. int count = 0;//创建一个返回值count
  18. // Pattern p = Pattern.compile("\\s");//将给定的正则表达式编译并赋予给Pattern类
  19. Pattern p = Pattern.compile("\\+");//将给定的正则表达式编译并赋予给Pattern类
  20. Matcher m = p.matcher(str);//生成一个给定命名的Matcher对象
  21. while(m.find()){//查找类似于Matcher对象的字符
  22. count++;//count自加作为标记
  23. }
  24. return count;//返回count值
  25. }
  26. }