java - Regex is returning undesired results -
i trying capture group regex follow pattern:
ex1 - anyanyany
group 1 have anyanyany
ex2 - anyanyany.abcany
group 1 have anyanyany
ex3 - anyany.abcde.fghi
group 1 have anyany.abcde
when try (.+)(?:\.)
, returns ex2 , ex3. if change (.+)(?:\.)*
returns same string of input.
i don't know have solve it. me? knowledgement missing?
try non-greedy regex.
(.+?)(?:\.[^.]*)?$
in java need escape backslash 1 more time, like,
pattern p = pattern.compile("(.+?)(?:\\.[^.]*)?$");
Comments
Post a Comment