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