I need to capture the optional texts in a pattern, with the extracted examples i
, 9
, Caffè
and you
in the following matched scenarios:
Valid matches:
love! 9 love! love Caffè! i love you!
Invalid matches:
love iloveyou
My rule: [*] love [*]!
, with [*]
meaning blank text can be accepted to be captured.
I tried to make the regex ((?:.+) )?love( (?:.+))?!
(online) but it failed to capture the correct texts.