Negative lookbehind


Note: Content might be outdated!

#TIL about negative lookbehind in Regular Expressions. 🤯

✅ Must match: /something/
✅ Must match: /something/?utm_wtf=yo
❌ Must not match: /another/something/
👉 Does the trick: \/(?<!\w\/)something\/?([\?+].*)?

(Ok, and I also learned it’s bad performance, so don’t use it unless absolutely necessary.)

3 reactions on “Negative lookbehind

  1. Not sure the context, but does the trick as well

  2. Very peculiar context in this case, so yes, a whole lot of better approaches in more regular scenarios.

Reactions are closed.


  • 💬 Adedayo Jibi Adeniyi