I have the following string format:
[[TEXT|TEXT]] <-- the "|TEXT" is optional
And so far what works fine is:
/([^\[]+)(?=\]\])/
Which will return:
TEXT
or
TEXT|TEXT
I want to match up to “|TEXT” if it has been included and only ever match the left side of “|” or “]]” depending on which is first.
Any suggestions?
UPDATE – if you only want to match what’s in the
[[]]and not including the|TEXTif it’s there, try this:Which is more-or-less your starting regex but it stops at a
|or a]].Or if your regex flavour supports look-behinds you could do:
This just enforces that you match from
[[onwards. Not really necessary but a bit more unknown-content-proof.