---
title: "正则表达式统计字符串出现的次数"
author: "ChineseThink"
date: "2012-06-07T08:10:13Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-06-07T08:10:13Z"
id: 1553901
url: "https://chinesethink.iteye.com/blog/1553901"
---

```java
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);
		
	}

}
```


正则表达式几乎在各种语言中都有实现，特别是对于做一些简单的数据校验来说很方便很实用。