正则表达式统计字符串出现的次数

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

public class RegexExpression {

	public static void main(String[] args) {
		//测试数据
		String str = "fsdfeofkldfleierueo";
                //e表示需要匹配的数据,使用Pattern建立匹配模式
		Pattern p = Pattern.compile("e");
                //使用Matcher进行各种查找替换操作
		Matcher m = p.matcher(str);
		int i = 0;
		while(m.find()){
			i++;
		}
		
		System.out.println(i);
		
	}

}


正则表达式几乎在各种语言中都有实现,特别是对于做一些简单的数据校验来说很方便很实用。

你可能感兴趣的:(正则表达式,regex,regexexpression)