Hi I was hopeing that someone can help me with this regex.
I want to match the patern below once to extract meta keywords from a page:
.match(/(<meta name=[\"|\']keywords([^\/>]*))/ig);
Any ideas will be welcomed
Hi I was hopeing that someone can help me with this regex.
I want to match the patern below once to extract meta keywords from a page:
.match(/(<meta name=[\"|\']keywords([^\/>]*))/ig);
Any ideas will be welcomed
Why can't you use a DOM parser and then just extract all the meta elements and iterate through and do whatever you want?
I don't have specific answer, but is this helpful? It is what I use in TextPad's find and replace.
^<meta[^"]+"\([^"]*\)"[^"]*"\([^"]*\)"*.*
FIND:
^[^"]+"\([^"]*\)"[^"]*"\([^"]*\)"*.*
REPLACE:
<\1>\2</\1>
CHANGES:
<TITLE>Q10022</TITLE>
<META HTTP-EQUIV="CONTENT-Type" CONTENT="text/html; charset=iso-8859-1" />
TO:
<TITLE>Q10022</TITLE>
<CONTENT-Type>text/html; charset=iso-8859-1</CONTENT-Type>
<meta name="keywords" content="(.+)" />
I may be wrong but if it's non-greedy that should be it. just escape the special characters.
This is untested but with jquery couldn't you just do:
$('meta').each(function() { // insert code here to put the attributes in an array or whatever });
and then inside there either store the data, do some ajax calls or some actions based on the data in each of the meta tags.