正则表达式提取 替换

xiaoxiao2026-06-15  6

//提取public void regExp(){ String hqlString = "select * from User where username = xuly and password = 1111"; Pattern pattern = Pattern.compile("(username\\s=\\s\\S*)"); Matcher matcher = pattern.matcher(hqlString); while (matcher.find()) { System.out.println(matcher.group(1)); } }//替换 @Test public void replace(){ String hqlString = "select * from User where username = ? and password = ?"; Pattern pattern = Pattern.compile("\\?"); Matcher matcher = pattern.matcher(hqlString); System.out.println(matcher.replaceAll("values")); }
转载请注明原文地址: https://www.6miu.com/read-5050181.html

最新回复(0)