in reply to Re: Return multiple matches in file
in thread Return multiple matches in file

Hi Dave--thanks for getting back to me!

I actually got the script off of this site (http://www.perlmonks.org/?node_id=98208)

I am searching for: "img alt="" src=" and would like the script to then return the 10 characters after that.

Below is a sample of the text I am going through. For this example, it will only return the first (<img alt="" src="http://www.xyz/12345.jpg"), and not any other matches. Am I going about this the correct way, or would some sort of wildcard search be easier?

<img alt="" src="http://www.xyz/12345.jpg" original-title="lol&lt;p&gt +;&lt;span class='points-vkL2Q'&gt;497&lt;/span&gt;&nbsp;&lt;span clas +s='points-text-vkL2Q'&gt;points&lt;/span&gt; : 456 : 4 days&lt;/p&gt; +"></a><div class="hover"><div class="arrows"><div title="like" class= +"arrow up " data="vkL2Q" type="image"></div><div title="dislike" clas +s="arrow down " data="vkL2Q" type="image"></div></div></div></div><di +v id="mSHi8" class="post"><a href="/gallery/mSHi8"><img alt="" src="h +ttp://i.xyz.com/mSHi8b.jpg"

Replies are listed 'Best First'.
Re^3: Return multiple matches in file
by davido (Cardinal) on Jun 14, 2011 at 00:09 UTC

    At minimum change your string to $string = quotemeta 'String to search for';. quotemeta, which ensures that $string is interpreted as a literal string, rather than having the characters you're searching for be mistakenly seen as regexp special characters.

    But just a couple days ago I was playing with HTML::LinkExtor, and I have to say, I think it's a much more robust solution for what you're trying to accomplish. It wouldn't exactly fit your specification, but it would probably be such a nice solution that you would reconsider how to solve the greater problem.

    By the way, that code you found in Categorized Questions and Answers is... well, at best outdated. That's why I was asking. Embarrassing that it still sits there in Q&A. I took the liberty of updating the Q&A post with some more up to date code.


    Dave