Parsing og: tags with ColdFusion regex -
Parsing og: tags with ColdFusion regex -
if 1 wants extract/match open graph (og:) tags html, using regex (and coldfusion 9+), how 1 go doing it?
and tricky bit is has cover both possible variations of tag formation in next examples:
<meta property="og:type" content="website" /> <meta content="website" property="og:type"/>
so far got this:
<cfset tags = rematch('(og:)(.*?)>',html_content)>
it match both of links, first type has content bit returned it. , content require.
just create absolutely clear, desired output should array of og tags (they 'type,image,author,description etc.). means should flexible , not based on og:type illustration alone.
of course of study if it's possible, ideal output struct first column beingness name of tag, , sec containing value (content). can achieved post processing , not of import extracting tags themselves.
cheers, simon
so want array ['og:author','og:type', 'og:image'...]?
try using regex og:([\w]+)
that should give start. have duplicates if have 2 of same og:foo meta tags.
you can @ jsoup help parse html you. makes lot easier.
there few blog posts on using in cfml
jquery-like parsing in java
parsing, traversing, , mutating html coldfusion , jsoup
regex coldfusion
Comments
Post a Comment