I used this regex expression to search for img src in a string in one on my site.
Now I wan’t to use this expression to do the same thing in objective c. How can I do that using RegexKitLite?
This is my expression
/<img.+src=[\'"]([^\'"]+)[\'"].*>/i
@Tim Pietzcker
Your code works great but for example if I try to search img in this string
<p><a href="http://www.nationalgeographic.it/popoli-culture/2011/08/03/news/per_la_tomba_del_boia-443612/?rssimage"> <img src="http://www.nationalgeographic.it/images/2011/07/29/115624013-20034abf-4d91-40fe-98ab-782f06a9854d.jpg" width="140" align="left" hspace="10"></a>Scoperta in America del Sud la sepoltura pre-incaica di un uomo circondato da coltelli cerimoniali che secondo gli archeologi eseguiva sacrifici umani</p>
I have this result in my array:
matchArray: (
"<img src=\"http://www.nationalgeographic.it/images/2011/07/29/115624013-20034abf-4d91-40fe-98ab-782f06a9854d.jpg\" width=\"140\" align=\"left\" hspace=\"10\">"
)
How can I mod your regex to only get the content of src tag? thank you so much
The
/delimiters are throwing you off. Also, you should at least use lazy quantifiers. Try this:This breaks when filenames contain quotes, by the way. Could that be a problem for you?
A regex that’s a bit safer (and that handles quotes well) would be
However, now the matches filename will be in capture group 2, not 1, so you need to modify any code that uses the filename after the match.