I am new to javascript and regular expressions.So sorry if this question looks silly.
I want to use negative lookahead to find last matched word in a string. Pattern is dynamic i.e. it may change.
Ex Find "foo" in "this foo is not same foo" here regex should return index of last "foo". To find it I used foo(?!.*foo) negative lookahead. But I need to keep "foo" in variable so that i can find other pattern also.
I am trying to use RegExp() constructor to use variables but unable to find ways in which i can use negative lookahead syntax.So is there any way to use negative lookahead in RegExp constructor ? If yes, what is it ?