ITeye博客

Java正则表达式摘录

xdlvpei · 2010-04-13 09:48 · Java Core · 编程语言 · Markdown

正则表达式30分钟入门教程 http://deerchao.net/tutorials/regex/regex.htm javascript 正则表达式-司徒正美 http://www.cnblogs.com/rubylouvre/archive/2010/03/09/1681222.html Java正则表达式详解 http://edu.yesky.com/edupxpt/18/2143018.shtml 常用的正则表达式 http://www.aslibra.com/doc/regex.htm

应用代码:


java.util.regex.Pattern p2 = java.util.regex.Pattern.compile("([a-za-z]+[1-4]{0,1})=");
java.util.regex.Matcher m = p2.matcher(query);
StringBuffer sb = new StringBuffer();
while(m.find()){				  m.appendReplacement(sb,m.group(1).toUpperCase()+"=");
}
m.appendTail(sb);
query_input = sb.toString();


	public static void main(String[] args) {
		Pattern p = Pattern.compile("(TS:\\(\\S*\\))");
		 Matcher m = p.matcher("(TS:(1) OR PC:(ab))");
		 StringBuffer sb = new StringBuffer();
		 while (m.find()) {
		     m.appendReplacement(sb, "TI:(1) OR AB:(1)");
		 }
		 m.appendTail(sb);
		 System.out.println(sb.toString());
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。