I want to match '|| C \n' in the following string:
|| A || B || C \n
With a regexp that is something like '\|\|not(\|\|).*?\n', so that all '||' are excluded except the last one.
How does one do this?
I want to match '|| C \n' in the following string:
|| A || B || C \n
With a regexp that is something like '\|\|not(\|\|).*?\n', so that all '||' are excluded except the last one.
How does one do this?
You can't just look for 2 bars, then make sure no other double bars exist.
Have to protect against a triple bar |||
first.
\|\|(?!\|)[^|]*(?:\|(?!\|)[^|]*)*$
Readable version
\|\| # Double bar
(?! \| ) # Cannot be a third bar
[^|]* # Optional non-bars
(?: # Cluster
\| # Bar
(?! \| ) # if not followed by bar
[^|]* # Optional non-bars
)* # End, optionally 0 to many times
$ # EOS