0

For parsing headers of Wikipedia article sections I'd like to have a regex match anything except two or more equal signs ==.

For this I tried this regex: ([^==]+) but it only checks for a single equal sign character (same as ([^=]+)). Negative lookaheads also didn't work for this so far.

How can one use regex to match everything except of a specified string?

mYnDstrEAm
  • 751
  • 2
  • 8
  • 26
  • 1
    Are you looking for `(?:(?!==)[^])*`? – Wiktor Stribiżew Mar 07 '19 at 13:45
  • So if the header is "something something", that's OK, but if the header is "something==something" or "something===something", then those should be rejected? If so, one thing I just learned in JavaScript is the search method (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) where "something something".search(/==+?/g) will return -1, but "something==something".search(/==+?/g) will return 9. – Doug F Mar 07 '19 at 13:51
  • @WiktorStribiżew: Yes! That's exactly what I was looking for, thanks! If the question is fine and shouldn't be deleted you should have posted it as an answer so that I can mark it as solved. Will reference you in the issue or pull request that fixes this in WikiJs. – mYnDstrEAm Mar 07 '19 at 14:02

0 Answers0