1

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);
2
  • Your question is unclear. Please show several examples of "before" and "after" strings, i.e. the input and desired output. Commented Jul 2, 2015 at 5:52
  • what you actually want to replace can you please say that with more example. .? Commented Jul 2, 2015 at 6:03

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

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.