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?

4

1 回答 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';
于 2013-03-30T19:16:26.877 回答