Regex to grab keywords from HTML header

D

Digital.Rebel.18

I'm trying to figure out how to extract the keywords from an HTML
document.
The input string would typically look like:
<meta name='keywords' content='word1, more stuff, etc'>

Either single quotes or double quotes can be used and there can be any
number of spaces or returns between any element. Keywords can contain
special characters except for a comma or a closed bracket. For
example, the HTML might be:

<
meta name =
'
keywords'
content=
"word1 ,
more
stuff
,
etc"
The coolest thing would be to have a routine actually return one
keyword at a time (the keywords are separated by commas) However, I'd
be happy just to have the routine return only the keywords w/o all the
rest of the surrounding HTML.

Here's what I've tried so far for a Regex string.

"[<][\s\n\r\t]*meta[\s\n\r\t]name[\s\n\r\t]*='[\s\n\r\t]*'[\s\n\r\t]*keywords[\s\n\r\t]content[\s\n\r\t]*=[\s\n\r\t]*'[^>]'[\s\n\r\t]*>"

It's not working very well :) (this regex stuff is complicated!)

Can anybody help a regex newbie?
 
B

Boni

You might want to try Expresso
http://www.ultrapico.com/
or
Regulator (look at google to find out the address)
HIH

I'm trying to figure out how to extract the keywords from an HTML
document.
The input string would typically look like:
<meta name='keywords' content='word1, more stuff, etc'>

Either single quotes or double quotes can be used and there can be any
number of spaces or returns between any element. Keywords can contain
special characters except for a comma or a closed bracket. For
example, the HTML might be:

<
meta name =
'
keywords'
content=
"word1 ,
more
stuff
,
etc"
The coolest thing would be to have a routine actually return one
keyword at a time (the keywords are separated by commas) However, I'd
be happy just to have the routine return only the keywords w/o all the
rest of the surrounding HTML.

Here's what I've tried so far for a Regex string.

"[<][\s\n\r\t]*meta[\s\n\r\t]name[\s\n\r\t]*='[\s\n\r\t]*'[\s\n\r\t]*keywords[\s\n\r\t]content[\s\n\r\t]*=[\s\n\r\t]*'[^>]'[\s\n\r\t]*>"

It's not working very well :) (this regex stuff is complicated!)

Can anybody help a regex newbie?
 
V

Veign

Try one of the many RegEx sites:

How To Use Regular Expressions in Microsoft Visual Basic 6.0
http://support.microsoft.com/default.aspx?scid=kb;en-us;818802

RegEx Tutorial for VB:
http://juicystudio.com/tutorial/vb/regexp.asp

RegEx Library:
http://www.regexlib.com/

RegEx Module for VB:
http://www.aivosto.com/regexpr.html

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


I'm trying to figure out how to extract the keywords from an HTML
document.
The input string would typically look like:
<meta name='keywords' content='word1, more stuff, etc'>

Either single quotes or double quotes can be used and there can be any
number of spaces or returns between any element. Keywords can contain
special characters except for a comma or a closed bracket. For
example, the HTML might be:

<
meta name =
'
keywords'
content=
"word1 ,
more
stuff
,
etc"
The coolest thing would be to have a routine actually return one
keyword at a time (the keywords are separated by commas) However, I'd
be happy just to have the routine return only the keywords w/o all the
rest of the surrounding HTML.

Here's what I've tried so far for a Regex string.

"[<][\s\n\r\t]*meta[\s\n\r\t]name[\s\n\r\t]*='[\s\n\r\t]*'[\s\n\r\t]*keywords[\s\n\r\t]content[\s\n\r\t]*=[\s\n\r\t]*'[^>]'[\s\n\r\t]*>"

It's not working very well :) (this regex stuff is complicated!)

Can anybody help a regex newbie?
 
D

Digital.Rebel.18

Woohoo! Great reference Boni!

Here's the regex string that returns the keywords:


<\s*meta\s*name\s*=\s*"\s*keywords\s*"\s*content\s*=\s*"\s*([^"]+)"\s*>

This makes a lot more sense now...

Is there a way to further parse the keywords inside the ([^"]+)
adding to the string above?

Keywords are listed as
at least one keyword (ending in either quote or comma)
if it ends with a quote, then throw away the quote and we're done.
if it ends in comma then look for repeating groups of [,next keyword]
and throw away the comma each time

I've looked at a number of tutorials online and this part is more
complicated

Note: Veign - the "jucystudio" reference 404'd out :(
 
M

Michael Cole

I'm trying to figure out how to extract the keywords from an HTML
document.
The input string would typically look like:
<meta name='keywords' content='word1, more stuff, etc'>

You have posted this to both a dotnet group and a VB Classic group - the two
are different languages. You need to specify which language you are using,
because...


--
<response type="generic" language="VB.Net">
This newsgroup (.vb.syntax) is for users of Visual Basic version 6.0
and earlier and not the misleadingly named VB.Net
or VB 200x. Solutions, and often even the questions,
for one platform will be meaningless in the other.
When VB.Net was released Microsoft created new newsgroups
devoted to the new platform so that neither group of
developers need wade through the clutter of unrelated
topics. Look for newsgroups with the words "dotnet" or
"vsnet" in their name. For the msnews.microsoft.com news
server try these:

microsoft.public.dotnet.general
microsoft.public.dotnet.languages.vb

</response>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top