0

I have some javascript that I need assistance with where I want to update a string with javascript.

Original string:

987654321-200x200-1_This+is+text.jpg

Want it to end up to be:

not_found-200x200.jpg

So 987654321 gets replaced with not_found and -1_This+is+text with nothing.

Note the original string is fully dynamic with only the - x - _ + constant in all.

I have tried something like this:

'987654321-200x200-1_This+is+text.jpg'.replace(/\_\d{0,}[A-Za-z]*/, '_not_found') 

but need help with the regexp to achieve this. Anyone help?

2
  • Why don't you split on - and take the second array item? Commented Mar 30, 2013 at 19:15
  • @JaredFarrish - my thoughts exactly ! Commented Mar 30, 2013 at 19:17

1 Answer 1

4

Not sure if this will do, but if all you're looking for is 200x200 you could just split on - and use that :

var str = '987654321-200x200-1_This+is+text.jpg';
var not = 'not_found-' + str.split('-')[1] + '.jpg';
Sign up to request clarification or add additional context in comments.

1 Comment

Boo. Too slow. I had: ['not_found-', '987654321-200x200-1_This+is+text.jpg'.split('-')[1], '.jpg'].join('')

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.