Domanda

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.

È stato utile?

Soluzione

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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top