So here's the problem:
I have a html document that is being spit out to me as a string.
example: "<!doctype html>\n<html lang=\"en\">\n <head>\n</head>\n
<body>\n \t<header>\n \t <hgroup>\n \t <h1 class=\"my-class\">My
page Testing</h1>\n<p class=\"my-class icon\">some text here</p>
\t<footer>\n \t <p class=\"fred my-class\">This is my footer
info</p>\n \t</footer>\n </body>\n</html>"
I'm using regular expression to find all the opening tags of the dom
elements. <html lang=\"en\">, <head>, <body>, <h1 class=\"my-class\">,
etc... and it's working. This is via scan() method.
···
==============================
elements = []
opening_tags = file.scan(/<\w+\s+[^>]*>/)
opening_tags.each do |tag|
if tag.match(/class=\\"(.*?)editor(.*?)\\"/) # tries to match anything
with a class="editor"
close = get_closing_tag(tag)
# finds which DOM element it is and returns close tag
# example if '<p class="my-class">' returns '</p>'
file.match(/#{tag}(.+)#{close}]/) { |m| elements << m }
# pushes all matches to elements array
=======================================
So I get the opening tags as it should
<h1 class=\my-class\"> and <p class=\"fred my-class\">
and I get a proper closing tag for each
</h1> and </p>
but /#{tag}(.+)#{close}]/ returns nothing
Output from Rails.logger.info
+++++++++++++++++++++++++++++++++++++++
==== tag ====
"<h1 class=\"my-class\">"
==== close ====
"</p>"
==== /#{tag}(.+)#{close}]/ ====
/<p class="my-class">(.+)<\/p>]/
==== tag ====
"<p class=\"my-class icon\">"
==== close ====
"</p>"
==== /#{tag}(.+)#{close}]/ ====
/<p class="my-class icon">(.+)<\/p>]/
==== tag ====
"<p class=\"fred my-class\">"
==== close ====
"</p>"
==== /#{tag}(.+)#{close}]/ ====
/<p class="fred my-class">(.+)<\/p>]/
======= elements ========
[]
+++++++++++++++++++++++++++++++++++++++
Any help would be appreciated. I'm at my wits end here. If there is a
completely better way to do this, I'm all ears as well.
Thank you in advance.
--
Posted via http://www.ruby-forum.com/.