From: William James Date: 2008-03-01T04:05:04+09:00 Subject: Re: Need a regex searching html code On Feb 29, 7:50 am, Mark Thomas wrote: > All the regex solutions provided will break with the following > perfectly valid HTML: > >
>
Tagline:
> Yippee Ki Yay Mo - John 6:27 >
Easily fixed. def find_header header, html html.scan( %r{(.*?)}im ).flatten. each{|s| return $1.strip if s =~ %r{#{header}(.*)}im } return nil end > > This is one of many reasons it is a BAD idea to use regexes to parse > HTML. Regular expressions are simply not the right tool for the job. Who told you that they are not? And why did you take his word for it? Does hpricot use regular expressions?