In javascript, I’m trying to capture some optional groups but I always struggle with regular expressions!
I don’t know how to allow for any characters to appear between capture groups
This is what I have so far:
/(((.*?)))+([(.*?)])?(<<(.*?)>>)?(|(.*?)|)?/g
It’s supposed to capture anything between (), then optionally anything between [], then optionally anything between <<>> and finally, optionally anything between ||
Running that expression over this string….
Presentation on <strong>(date)[presentation-date]<<&today>></strong>|{"placeholder":"Type summary"}|
…captures (date), [presentation-date] and <<&today>> but it doesn’t capture |{"placeholder":"Type summary"}|
I’ve worked out that it’s because of the </strong> between <<&today>> and |{"placeholder":"Type summary"}| but I don’t know how to allow for any characters to be between the optional capture groups (<<(.*?)>>) and (|(.*?)|)
I’ve tried different placings of (?:.*) in the hope that would ignore anything between capture groups but I still can’t get it to work.
Can anyone please show me what I’m missing?



