I’m trying to mimic a look behind in Javascript,
I want to match the string “object.all” but not “object.call”. I’ve tried:
new RegExp('(?!(\\.))all')
But both examples are matched, what I want is a look behind to test if there’s a . (dot) just behind all, can someone explain me what’s wrong in my regex?
Thanks in advance
This one is good:
'object.all'.replace(new RegExp('(?!(\\.))all'), 'foo')
// => object.foo
For this one i expect the result to be “object.call” :
'object.call'.replace(new RegExp('(?!(\\.))all'), 'foo')
// => object.cfoo
Though this seems complex this will get the job done:
I have used the article (Mimicking Lookbehind in JavaScript) that @m.buettner linked in the comments before in a bit of code I was working on earlier this year.