From: Jari Williamsson Date: 2008-03-01T04:41:01+09:00 Subject: Re: Need a regex searching html code Florian Gilcher wrote: > > 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=~/
puts "Within H5 tags: #{line}" if (line=~/
end > > It doesn't see the second
as it considers _both_ divs closed. It consider the first div closed. It never sees the other one. Best regards, Jari Williamsson