I need to detect class of strings which must include X, but may have Y optionally.
<<TAG##X#123>>
<<TAG##X#123##Y#456>>
So here’s the regex I tried, greps x but can’t detect y value:
(<<)(TAG##X#(?<x>.+)(##Y#(?<y>.+))?)(>>)
What am I missing?
>Solution :
(?<x>.+) matches the whole 123##Y#456 already.
Add a ? after the quantifier, to make this ungreedy: (?<x>.+?)
https://regex101.com/r/UuT50e/1