Is there a way to achieve the equivalent of a negative lookbehind in javascript regular expressions? I need to match a string that does not start with a specific set of cha
Using your case, if you want to replace m
with something, e.g. convert it to uppercase M
, you can negate set in capturing group.
match ([^a-g])m
, replace with $1M
"jim jam".replace(/([^a-g])m/g, "$1M")
\\jiM jam
([^a-g])
will match any char not(^
) in a-g
range, and store it in first capturing group, so you can access it with $1
.
So we find im
in jim
and replace it with iM
which results in jiM
.