0

How would I write this to store the text "allofthistextcaptured" with regex? i dont want "_poster" to be captured. The below javascript is exactly what I need, I just need some regex at the end to capture all the text in the src tag EXCEPT "_poster".

html

<div class="postImage"><img src="allofthistextcaptured_poster.jpg" title="" width="640" height="385" /></div>

js i have so far

var text = $(this).siblings('.postImage').find('img').attr('src');

3 Answers 3

4

Will a simple replace() work for you?

var text = $(this).siblings('.postImage').find('img').attr('src').replace('_poster', '');

If you want to use RegExp then you can do something like this:

var text = $(this).siblings('.postImage').find('img').attr('src').replace(/_poster./, '.');

Which looks for _poster. and replaces it with . but this is pretty-much the same thing as the first example.

Here's a demo: http://jsfiddle.net/exAXw/

Sign up to request clarification or add additional context in comments.

1 Comment

Agreed, simple replace is much cleaner than regex here.
0

Seeing as the searchable string is reduced to only the filename, you can use this regex to capture the name and the extension:

([\w]+)(?>_poster)\.([\w]+)

Comments

0

Just a generic replace using regEx to strip b/w k and . that is anything after _ and before .

.replace (/(_[^.*]*)/, '');

DEMO

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.