Search code examples
javaregexregex-greedy

Java Regexp Groups


I need a expression to extract some alternatives. The input is:

asd11sdf33sdf55sdfg77sdf

I need the 11 33 and 55 but not 77.

I tried first:

.*(((11)|(33)|(55)).*)+.*

So I got only 55. But with lazy (non greedy)

.*?(((11)|(33)|(55)).*)+.*

I got only 11. How to get all?

regards Thomas


Solution

  • Use (?!77)(\d\d) as a Pattern and while (m.find()) { m.group(1) } where m is a Matcher.