I have a string:
"/upload/c_fill,w_960,h_640/v1430399111/"
Where i want to replace wherever "w_" to some other value, say w_960 to w_930 while 960 could be vary.
i tried following but not able to find string end with:
var imgPath = elemPath.replace(/(\,w_)/, ",w_"+930);
If I understand you correctly you wanted to replace ,w_
followed by three digits with ,w_930
. You were on the right track. You can use \\d
to match a digit and {3}
for three repetitions. Also you don't need the group ()
or to escape the comma:
var imgPath = elemPath.replace(/,w_\d{3}/, ",w_"+930);
If the number of digits can vary, use +
(one or more repetitions):
var imgPath = elemPath.replace(/,w_\d+/, ",w_"+930);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.