public static void main(String[] args) {
// 查找的字符串
String str = "select t.id,t.name from urrp_db.imas_xmhk_ll t left join urrp_db.imas_ckbx_bl a on t.id=a.id";
//Java正则表达式以括号分组,第一个括号表示以"IMAS_"开头,第三个括号表示以" "(空格)结尾,中间括号为目标值,
Pattern p = Pattern.compile("(IMAS_)(.*?)( )");
Matcher m = p.matcher(str.toUpperCase());
while(m.find()){
// 取出目标值
String matchStr = m.group(2);
System.out.println("匹配内容:"+matchStr);
str = str.toUpperCase().replace(matchStr,matchStr+"_HL");
System.out.println(str);
}
}
运行结果: