CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Need help with regular expression

 



lazyme
New User

Mar 10, 2010, 9:46 PM

Post #1 of 4 (3127 views)
Need help with regular expression Can't Post

I have the strings in the format below


Code
<a  id="thumbTitle_browse_1" class="thumbTitle maxLines2" href="/browse/videos/category/comedy/watch/e177035tNrcdHRj" title="Family Guy: Season 4 Review!" onclick="return handleVideoClick(this);"> 
Family Guy: Season 4 Review! </a>


<a id="thumbTitle_browse_2" class="thumbTitle maxLines2" href="/browse/videos/category/entertainment/watch/v2353068cFYxqHtK" title="family guy" onclick="return handleVideoClick(this);">
family guy </a>



I need to read the value inside the <a> </a> tags. Consider $string has one of these string. I am trying to write a regular expression as


Code
$image3 =~ m{<a  id="thumbTitle_browse_.".*>(.*?)<\/a>}gsi


So that the value would be stored as $1. However the expression is not correct. Can someone please help me define the regular expression.

Thanks


FishMonger
Veteran / Moderator

Mar 11, 2010, 5:39 AM

Post #2 of 4 (3108 views)
Re: [lazyme] Need help with regular expression [In reply to] Can't Post

Don't use a regex.

Use an HTML parser.

http://search.cpan.org/search?query=HTML%3A%3ATokeParser&mode=all


rovf
Veteran

Mar 11, 2010, 6:41 AM

Post #3 of 4 (3100 views)
Re: [lazyme] Need help with regular expression [In reply to] Can't Post

FishMonger is right, but if you want to use a regexp, I think you should make the first .* non-greedy too.


roolic
User

Mar 22, 2010, 11:17 PM

Post #4 of 4 (3000 views)
Re: [FishMonger] Need help with regular expression [In reply to] Can't Post

my @a_teg_contents = ($string =~ /<a[^>]*thumbTitle_browse[^>]*>(.*?)<\/a>/gi);

NB: the /g option usage will cause returning an array of found substrings, the /s option is useless unless you use the variable within the regex (like =~ /$re/ )

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives