I'm using RegExp in some javascript code which I'm using to replace a string that looks like this:
[1]
With one that looks like this:
[2]
This all works OK, however I would only like to do this, if the preceding character is not a:
]
So
something[1] should become something[2]
But
something[1][somethingelse][1] should become something[2][somethingelse][1]
My current code looks like this:
var first = 1;
var count = 2;
var pattern = escapeRegExp("[" + first + "]");
var regex = new RegExp(pattern, 'g');
$(this).html().replace(regex, '['+count+']'));
Any advice appreciated.
Thanks