In my code at the point pattern = compiler.compile("(?<=,)[0-9]+(?=,)");
MalformedPatternException will occur Can I use look-behind? look-ahead is OK public static void main(java.lang.String[] args) { int groups; PatternMatcher matcher; PatternCompiler compiler; Pattern pattern; PatternMatcherInput input; MatchResult result; compiler = new Perl5Compiler(); matcher = new Perl5Matcher(); StringBuffer matchResult = new StringBuffer(""); try { pattern = compiler.compile("(?<=,)[0-9]+(?=,)"); } catch (MalformedPatternException e) { System.out.println("Bad pattern."); System.out.println(e.getMessage()); return; } input = new PatternMatcherInput("3,1-2223,6,7-8,9,10,11111-116166,9"); while (matcher.contains(input, pattern)) { result = matcher.getMatch(); System.out.println("Match: " + result.toString()); matchResult.append(result.toString() + " "); } System.out.println("finally we found this string"); System.out.println(matchResult); }