I’m trying to match this string:
Text 18 19 Text
With this regex:
\s+\d\d\s+
The string has two digits, each of them are surrounded by a leading and a trailing space.
So I’m thinking – this should give me 18 and 19 right?
It doesn’t, it only gives me only 18.
I’m testing with this tester here: http://java-regex-tester.appspot.com/
Thanks!
The reason that you do not match the second item is that the space between
18and19is consumed by the trailing\s+of the first match. You should make a non-consuming zero-width regexp for the trailing blank, for example by using the lookahead syntax or a token for zero-width boundary: