-1

How do I match a pair of double pipes (i.e. || text ||), while checking the content between the pipes for a singular pipe?

So, || text || matches " text ", while || spoiler2|spoiler|| matches " spoiler2|spoiler".

I've tried \|\|([^\|]+)\|\|, but that only matches the content without any further pipes between the two pipes.

Ildar Akhmetov
  • 1,231
  • 12
  • 21
Alex
  • 1
  • 2

1 Answers1

0

You can use a negative lookahead to ignore a pattern:

\|\|((?!\|\|).+)\|\|

The (?!\|\|) means to not match a || string.

Simon Doppler
  • 1,604
  • 7
  • 24