regex - Regular Expression substring start and end with JavaScript -
i have string:
"/upload/c_fill,w_960,h_640/v1430399111/"
where want replace wherever "w_" other value, w_960 w_930 while 960 vary.
i tried following not able find string end with:
var imgpath = elempath.replace(/(\,w_)/, ",w_"+930); 
if understand correctly wanted replace ,w_ followed 3 digits ,w_930. on right track. can use \d match digit , {3} 3 repetitions. don't need group () or escape comma:
var imgpath = elempath.replace(/,w_\d{3}/, ",w_"+930); if number of digits can vary, use + (one or more repetitions):
var imgpath = elempath.replace(/,w_\d+/, ",w_"+930); 
Comments
Post a Comment