I have Strings like the following:
"parameter: param0=true, param1=401230 param2=asset client: desktop"
"parameter: param0=false, param1=15230 user: user213 client: desktop"
"parameter: param0=false, param1=51235 param2=asset result: ERROR"
The pattern is parameter:
, then the param
's, and after the params either client:
and/or user:
and/or result
.
I want to match the stuff between parameter:
and the first occurrence of either client:
, user:
or result:
So for the 2nd String it should match param0=false, param1=15230
.
My regex is:
parameter:\s+(.*)\s+(result|client|user):
But now if I match the 2nd String it captures param0=false, param1=15230 user: user213
(looks like regex is matching greedy)
- How to fix this?
parameter:\s+(.*)\s+(result|client|user)+?:
won't fix it - With this regex tester I can add the modifier
U
to the regex to make regex lazy by default, is this possible in Java too?