Java正则表达式小记

http://blog.csdn.net/pipisorry/article/details/51059500

查找并抽取对应条件字符串

package Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
public static void main(String[] args) {
Test t = new Test();
t.test4();
}

public void test4() {
Pattern pattern = Pattern.compile("(.+?)\\(R(.+?)\\)");
Matcher matcher = pattern.matcher("avg(R4)");
if (matcher.find()) {
System.out.println(matcher.group(1));//分组的索引值是从1开始的,所以取第一个分组的方法是m.group(1)而不是m.group(0)。  
System.out.println(matcher.group(2));
}
}
}

avg
4

from: http://blog.csdn.net/pipisorry/article/details/51059500

ref: 


你可能感兴趣的:(java,正则表达式)