public static void main(String[] args) {
// 匹配 json= 这里 (所有字符) (t 后的字符(加 t))
String regEx = "json=(.*?)(t.+)";
String s = "json={'aa'='bb','cc'='dd'}ttest";
Pattern pat = Pattern.compile(regEx);
Matcher mat = pat.matcher(s);
//是否找到
if(mat.find()){
//获取整体
System.out.println(mat.group());
//获取第一个组匹配的
System.out.println(mat.group(1));
//获取第二个组匹配的
System.out.println(mat.group(2));
}
}
结果
json={'aa'='bb','cc'='dd'} test
{'aa'='bb','cc'='dd'}
test



