From: Florian Gilcher Date: 2008-03-01T04:33:52+09:00 Subject: Re: Need a regex searching html code On Feb 29, 2008, at 8:19 PM, Jari Williamsson wrote: > Mark Thomas wrote: >> All the regex solutions provided will break with the following >> perfectly valid HTML: >>
>>
Tagline:
>> Yippee Ki Yay Mo - John 6:27 >>
>> 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. > > Sorry if I'm missing the point: > --- > the_text = %q{ >
>
Tagline:
> Yippee Ki Yay Mo - John 6:27 >
> } > > the_text.each_line do |line| > puts "Within DIV tags: #{line}" if (line=~/
puts "Within H5 tags: #{line}" if (line=~/
end > --- > > Result: > Within DIV tags:
> Within DIV tags:
Tagline:
> Within H5 tags:
Tagline:
> Within DIV tags: Yippee Ki Yay Mo - John 6:27 > Within DIV tags:
> > > > Best regards, > > Jari Williamsson > This may work on this short snippet. Consider this: the_text = %q{
Tagline:
Yippee Ki Yay Mo - John 6:27
} the_text.each_line do |line| puts "Within DIV tags: #{line}" if (line=~/
as it considers _both_ divs closed. (which isn't even possible to determine, as we did not save any state). Second question: which
am I in at a certain point? Or, in other words: whats the #innerText of .info, whats the #innerText of .nextinfo? You won't get far without a stack and that can be proven [1]. If this is of interest to you, consider reading a book about computer theory. It may be hard stuff, but it pays off :).[2] Greetings Florian Gilcher [1] Up to the reader ;). [2] Don't feel bad if you didn't and don't consider this as an offense. I know many good programmers that never read any theory. But it certainly isn't bad to know about it.