`
caojianwei
  • 浏览: 13805 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌/上海
社区版块
存档分类
最新评论

关于java正则表达式的问题

阅读更多
public class TestString {
public static void main(String args[]) {

String str="For my money, the important thing about the meeting was bridge- buildingf";
String regEx="a*f";
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
System.out.println(m.replaceAll("1"));
}

}

问:我如何找到上述字符串,以a标记开始,f标记结束的子,a,f之间是任意字符的子串
分享到:
评论
2 楼 caojianwei 2007-06-16  
Thank You。
看来我以后还要多学习学习正则表达式。
1 楼 zrweng 2007-06-16  
		String str="For my money, the important thing about the meeting was bridge- buildingf";
		String regEx="a(.+?)f";
		Pattern p=Pattern.compile(regEx,Pattern.DOTALL);
		Matcher m=p.matcher(str);
		while(m.find()){
			System.out.println(m.group(1));
		}

相关推荐

Global site tag (gtag.js) - Google Analytics