3

I have various img src's like this: http://mydomain.com/wp-content/uploads/2012/10/img-80x93.jpg http://mydomain.com/wp-content/uploads/2012/10/image-80x110.jpg ...

I want to change them to: http://mydomain.com/wp-content/uploads/2012/10/img.jpg http://mydomain.com/wp-content/uploads/2012/10/image.jpg ...

Basically what I need is to remove from -80x until .jpg

I tried to remove "-80x" + all the numbers after that:

.replace('-80x'/\d+/g,''));

but didn't work... and others replaces but with no result.

Could you help me with this?

2
  • 1
    This has NOTHING to do with jQuery - it's plain-old JavaScript. Commented Nov 1, 2012 at 21:41
  • 1
    Take a look at my answer. I've edited it, it works now. Commented Nov 1, 2012 at 21:48

3 Answers 3

2

I think you just need the "-80x" to be inside your regex, like:

someString.replace(/-80x\d+/g,"")
Sign up to request clarification or add additional context in comments.

Comments

2
var source="http://mydomain.com/wp-content/uploads/2012/10/img-80x93.jpg";    
var url=source.split('-80x')[0]+".jpg";

it will give you "http://mydomain.com/wp-content/uploads/2012/10/img.jpg"

Comments

1

Edited:
This works.

.replace(/\-[0-9]+x[0-9]+\.jpg/g, '.jpg');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.