Ralph Shnelvar wrote in post #980334: > How can I do this? That is, I want to find the nearest <h1> ... </h1> > surrounding Placeholder2.
First, I'll +1 Fred on using Nokogiri for parsing HTML. But you can modify you regex so any markup '<' characters are excluded using [^<], as in: >> p = /<(h\d)>[^<]+Placeholder2.*?<\/\1>/ >> s = "xyz<h1>x P0 y</h1><h1>x Q1 y</h1><h1>1 Placeholder2 2</h1>abc" >> p =~ s => 33 >> $1 => "h1" Is that what you meant? - ff -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

