Forum Moderators: coopster & phranque

Message Too Old, No Replies

problem with regex matching

         

PsychoTekk

8:34 am on Jun 15, 2003 (gmt 0)

10+ Year Member



hi, i have a little sitesearch script, works fine so far
but i would like to add each pages meta description text
to the search results.
the following is the code i tried, it starts where it should
but does not end with the meta description's '">' but with
the last '">' on that page.
what does it have to look like to make $1 contain the metadesc text only?

if ($string =~ /<meta name=\"description\" content=\"(.*)\">/i)
{$mdesc{$FILE} = "$1";}

any help appreciated :)

ShawnR

9:27 am on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

/<meta name=\"description\" content=\"(.*?)\">/i)

By default a regex will eat as much of your string as it can. The '?' is the 'minimal quantifier', which says 'eat as little of the string as possible'. (Not a very technical explanation, but it is the way I think of it.)

Shawn

PsychoTekk

10:01 am on Jun 15, 2003 (gmt 0)

10+ Year Member



thanks Shawn, works great :)

ShawnR

10:25 am on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help :)