On Feb 8, 3:46 pm, Ralph Shnelvar <[email protected]> wrote:
> Consider the string
>
>   xyz<h1>x P0 y</h1><h1>x Q1 y</h1><h1>1 Placeholder2 2</h1>abc
>
> and the pattern
>
>   <(h\d)>.*?Placeholder2.*?<\/\1>
>
> the pattern matches
>   <h1>x P0 y</h1><h1>x Q1 y</h1><h1>1 Placeholder2 2</h1>
>
> I want it to match
>
>   <h1>1 Placeholder2 2</h1>
>
> How can I do this?  That is, I want to find the nearest <h1> ... </h1>
> surrounding Placeholder2.
>
Don't know if/how to bend ruby's regular expressions to do this but
trying to parse html with regular expressions is doomed to fail
eventually. Use something like nokogiri.

Fred

-- 
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.

Reply via email to