--000e0cd138a0a2d6d3048282b0ad Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Mar 23, 2010 at 7:48 PM, Pen Ttt <myocean135 / yahoo.cn> wrote: > there two bugs in my first program : > 1t's __END__ not _END_ > 2t's "elsif" not "elseif" > i change my program into > #the filename is: /home/pt/htmlscan_test.rb > HTMLRegexp =/(<!--.*?--\s*>)| > (<(?:[^"'>]*|"[^"]*"|'[^']*')+>)| > ([^<]*)/xm > > data =DATA.read > > data.scan(HTMLRegexp){|match| > comment,tag,tdata=match[0..2] > if comment > p ["Comment",comment] > elsif tag > p ["Tag",tag] > elsif tdata > tdata.gsub!(/\s+/,"") > tdata.sub!(/ $/,"") > p [ "TextData",tdata] unless tdata.empty? > end > } > __END__ > <!DOCTYPE HTML> > <HTML> > <BODY> > < A name="FOO" href="foo" attr >foo</A> > < A name="BAR" href="bar" attr >bar</A> > < A name=BAZ href=baz attr >baz</A> > <!-- > dummy > --> > <BODY> > </HTML> > > there is another problem too: > it can be run on netbeans ide6.8,got correct answer > ["Tag", "<!DOCTYPE HTML>"] > ["Tag", "<HTML>"] > ["Tag", "<BODY>"] > ["Tag", "< A name=\"FOO\" href=\"foo\" attr >"] > ["TextData", "foo"] > ["Tag", "</A>"] > ["Tag", "< A name=\"BAR\" href=\"bar\" attr >"] > ["TextData", "bar"] > ["Tag", "</A>"] > ["Tag", "< A name=BAZ href=baz attr >"] > ["TextData", "baz"] > ["Tag", "</A>"] > ["Comment", "<!--\n <A href=\"dummy\">dummy</A>\n -->"] > ["Tag", "<BODY>"] > ["Tag", "</HTML>"] > > but when i run it on terminal > pt@pt-laptop:~$ ruby /home/pt/htmlscan_test.rb > /home/pt/htmlscan_test.rb:20: syntax error, unexpected '<', expecting > $end > <!DOCTYPE HTML> > ^ > > what's the matter? > can you try it on your computer? > please help me. > -- > Posted via http://www.ruby-forum.com/. > > It works for me on 1.8.6, 1.8.7, and 1.9.1 http://img13.imageshack.us/img13/122/picture1svu.png --000e0cd138a0a2d6d3048282b0ad--