From: "Peña, Botp" Date: 2008-07-25T18:46:05+09:00 Subject: Re: Regexp Ruby selection From: touffik@gmail.com [mailto:touffik@gmail.com] # I'm trying to code a ruby script that select the content of a HTML # table in a HTML page. # I used rubular to test my regexp syntax which is # / ]*>(.*)  / the re is fine, you can use that # with rubular the result of my expression is : # Result 1 # 1. 12345678 # Result 2 # 1. SAN FRANCESCO DA PAOLA # Result 3 # 1. Via San Francesco Da Paola, 10 # Result 4 # 1. 10123 # Result 5 # 1. TORINO # etc.... # But with my script : # # File.open('D:/testt/1.txt', 'r') do |filein| # while line = filein.gets # p line if line =~ /]*>/ .. line # =~ /\/A / # end # fileout.puts p # end # end # I got this result # "12345678 \n" # "SAN FRANCESCO DA PAOLA \n" # "Via San Francesco Da Paola, # 10 \n" # "10123 \n" # "TORINO \n" you already got it, but you did not capture sample code & run, botp@botp-desktop:~$ cat test.rb File.open('test.txt') do |f| while line = f.gets if line=~/]*>(.*) / p $1 end end end botp@botp-desktop:~$ ruby test.rb "12345678" "SAN FRANCESCO DA PAOLA" "Via San Francesco Da Paola,10" "10123" "TORINO" # I thought the .. between 2 "line =~" was like (...) in rubular which # let catch the content ?? you are making it harder. keep it simple. # Moreover I would like to transform this html code in XML. But I can"t # find an idea how to transform these HTML line in XML. # # 12345678 # But there is no attribut 'name' or wathever in the so making and # match/replace would be difficult ? if the html is nicely formatted, you can loop through the table. if you want to be sure, try outputting all the data you can capture first. Then output that again with xml tags inserted. do not worry. xml, like html, is just text w tags. Manipulating text is a good learning exercise for ruby. kind regards -botp