---
title: "正则表达式统计字符串出现次数"
author: "gangwu"
date: "2009-05-27T17:14:34Z"
tags: ["正则表达式"]
slug: "untitled"
draft: false
lastmod: "2009-05-27T17:14:34Z"
id: 397431
url: "https://gangwu.iteye.com/blog/397431"
---

```
	public static void main(String[] args) {
		String str = "中国，美国，日本，朝鲜，中国，中国，美国，越南";
		String reg = "中国";
		Pattern p = Pattern.compile(reg);
		Matcher m = p.matcher(str);
		int i = 0;
		
		while(m.find()) {
			i++;
		}
		
		System.out.println(i);
	}
```