Question

Here's my Regex in C#:

(?<!\([\w\s]+)\bSWORD\b

I now need this in JavaScript. I'm a newbie to regex, so I have no idea how I would do this without the lookbehind. Any help would be appreciated.

Was it helpful?

Solution

Since you don't have a lookahead as well, there is a neat trick. Reverse the input string and apply the reversed regular expression:

\bDROWS\b(?![\w\s]+\()

If you want the position of the match in the actual input string, then you can find it as:

lengthOfInputString - (foundMatchPosition + lengthOfMatch)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top