论坛首页 Java企业应用论坛

关于java正则表达式的问题

浏览 2785 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-06-16   最后修改:2011-02-15
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之间是任意字符的子串
   发表时间: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));
		}
0 请登录后投票
   发表时间:2007-06-16  
Thank You。
看来我以后还要多学习学习正则表达式。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics