java 正则表达式
例1:找到ERR + 数字的所有组合
package test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class re { public static void main(String[] args){ String digitNumStr = "11A11、22A22、33A33、44B44、55B55const.ERR_ID:const.ERR1,const.ERR23"; Pattern digitNumP = Pattern.compile("const.ERR[0-9]+"); Matcher foundDigitNum = digitNumP.matcher(digitNumStr); while (foundDigitNum.find()) { String digitNumList = foundDigitNum.group(); System.out.println(digitNumList); } } }
结果
const.ERR1 const.ERR23