You need to match the number inside with something like:
replace(/\/s[0-9]+\//, '/s' + image_size + "https://stackoverflow.com/")
Here’s an example: http://jsfiddle.net/nfDea/
Another option is to capture the beginning and end only, in order to concatenate:
replace(/(\/s)[0-9]+(\/)/, "$1" + image_size + "$2");
If you are actually referring to a variable called uh
, then you need to use the following:
var re = new RegExp("/s(" + uh + ")/");
a = a.replace(re, "/s" + image_size + "https://stackoverflow.com/");
or
var re = new RegExp("(/s)" + uh + "(/)");
a = a.replace(re, "$1" + image_size + "$2");
1
solved Please help me on this javascript [closed]