0

I have the following code. I would like to adapt the current regex /wid=\d+(\.\d)*/g so that it matches wid=100&crop=0,0,960,650 and not just wid=100. How can I adapt it to do 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);
Larme
  • 24,190
  • 6
  • 51
  • 81
user1937021
  • 10,151
  • 22
  • 81
  • 143
  • 1
    What about your [last post](http://stackoverflow.com/questions/25367604/regex-of-a-string/25367674#25367652) that is exactly same. Share your views with guys who answered to make it clear. – Braj Aug 18 '14 at 16:37
  • You have commented nothing on answers of your last post. Why? – Braj Aug 18 '14 at 16:39
  • If your question is closed as a duplicate look at the answers to that question! If they don't pertain to your question then post on comment on your original question, do not repost your question – skamazin Aug 18 '14 at 16:44

3 Answers3

2

You can use this regex.

wid=.*?(?=")

Working demo

enter image description here

As skamazin pointed in the comment you could achieve the same by using below regex (it could improve the readability):

wid=.*?"
Community
  • 1
  • 1
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
  • I don't think you need that look-ahead. – skamazin Aug 18 '14 at 16:50
  • @skamazin it's an option. I used it to get all the content until the quote. If I removed my regex doesn't work. – Federico Piazza Aug 18 '14 at 16:51
  • As far as I can tell, [this](http://regex101.com/r/oS3cI4/2) is exactly the same and more readable. Perhaps my first comment wasn't clear; I meant you need the double quote but not inside a look-ahead – skamazin Aug 18 '14 at 16:57
  • 1
    @skamazin I see your point. Yup, you are right. I'll update my answer pointing that. Thanks for the tip. – Federico Piazza Aug 18 '14 at 17:03
1

How about this version: wid.*\d

http://regex101.com/r/rI7tE0/1

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
0

How about:

var regx = /wid=[^"]+/;
Toto
  • 89,455
  • 62
  • 89
  • 125