jquery - Regext to match part of a string -
i have following code. adapt current regex /wid=\d+(\.\d)*/g
matches wid=100&crop=0,0,960,650
, not wid=100
. how can adapt this?
html
<img class="image-resize" src="http://hugoboss.scene7.com/is/image/hugoboss/test%2dimg?wid=100&crop=0,0,960,650" name="mainimg" id="mainimg"/>
jquery
var regx = /wid=\d+(\.\d)*/g; currentwidth = src.match(regx); newwidth = 'wid=960&crop=0,0,960,650'; newsrc = src.replace(currentwidth, newwidth);
you can use regex.
wid=.*?(?=")
as skamazin pointed in comment achieve same using below regex (it improve readability):
wid=.*?"
Comments
Post a Comment