Gossamer Forum
Home : General : Perl Programming :

Regular Expression Help

Quote Reply
Regular Expression Help
Hi,

I am having trouble writing a regular expression to get the contents of meta tags from a page.

Here's what I use now
$results =~ m/\s?name="keywords"?.?content=\"([^>]*)\">/isg

And it doesn't extract keywords from time to time. Sometimes because they are written like
name="keywords"
content="asda"
and sometimes for no apparent reason.

Can someone help me with a better regexp that will be able to handle different ways people can write <meta name="keywords" content="asd">?

Or if someone can point me to a script that does something similar?
thanks in advance

------------------
Greg L
gregl@email.com
www.GLdev.com


Quote Reply
Re: Regular Expression Help In reply to
Try this:

Code:
$results =~ /<meta\s+name="keywords"\s+content="([^\"]*)">/i

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Regular Expression Help In reply to
thanks a lot

I've tested it with about 15 sites now and seems to get all the meta tags.

thanks again.

------------------
Greg L
gregl@email.com
www.GLdev.com


Quote Reply
Re: Regular Expression Help In reply to
No problem.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us