---
title: "Java正则表达式摘录"
author: "xdlvpei"
date: "2010-04-13T09:48:52Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2010-04-26T10:21:22Z"
id: 642427
url: "https://lvpei.iteye.com/blog/642427"
---

正则表达式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

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();

```


```java

	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());
	}

```