例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
本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/5947361.html,如需转载请自行联系原作者