var imgRE = new RegExp( '(<img[^>]+class=(['"])XXX\2
if ( imgRE.test( str ) ) {
// Here, RegExp.$1 should contain your "img" tag
}
Main Topics
Browse All TopicsHello, i need the regex to find an entire Html IMG Tag by giving only the class name.
I need to use Regex (not javascript getElementsByClass)
Can anyone tell me the correct regex string or the way to replace that:
Example - In the html code are:
ImageA <img alt="some" src="some" class="XXX" />
ImageB <img src="some" class="XXX" />
ImageC <img class="XXX" />
ImageD <img class="XXX" title="some" src="some" />
I need the code like
html = html.replace(REGEXCODENEED
To get the html result as:
ImageA ImageB ImageC ImageD
Any solution ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi HonorGod,
Near, but your Regex i think that doen't work:
Please go to:
http://www.regular-express
In the Replacement text put the string:
ImageA <img alt="some" src="some" class="XXX" />ImageB <img src="some" class="XXX" />ImageC <img class="XXX" />ImageD <img class="XXX" title="some" src="some" />
If you put the Regex str:
<img[^>]+class=(['"])XXX\2[^
That don't work
BUT i see that with:
<img[^>]+class=(['"])XXX[^>]*
Now work
Any case your JScript code:
var imgRE = new RegExp( '(<img[^>]+class=(['"])XXX\2
doest not work, its not well writed
Can you accurate the code
This:
/(<img[^>]+class=([\'\"])XXX
works just fine here:
http://regexpal.com/
The error with the earlier one was that I had failed to escape the single and double quotes... sorry.
sorry don't work for me, dont' work at regexpal, dont work at http://www.regular-express
Can you try on thelast one (http://www.regular-expres
and tell me the code like:
var imgRE = new RegExp( '(<img[^>]+class=(['"])XXX\2
But corrected and working
The \2 says to match the same pattern that occurred in the 2nd group.
Groups are indicated by open parenthesis '(', so the 2nd groups is the one that is used to find/match either an open single quote, or open double quote around the class name. So either of these would match:
'XXX'
"XXX"
I hope that this makes sense.
Thanks for the grade and points.
Good luck & have a great day.
Business Accounts
Answer for Membership
by: billprewPosted on 2009-09-26 at 17:18:49ID: 25432181
Wouldn't something like this work?
<img.*/>
~bp