Tim Hoolihan
6/16/2006 8:51:00 PM
put in a file news.txt:
news.test.com
news.test1.com
run this script:
#dump out the file
newstext = File.open("news.txt").read
puts "newstest:",newstext,"\n"
matches=newstext.scan(/(news\.[\S]+)\s/)
#dump out matches
puts "matches:"
matches.each{|m| puts m}
Une bévue wrote:
> ChrisH <chris.hulan@gmail.com> wrote:
>
>> I'd try:
>> matches = []
>> File.open(file,'r'){|f|
>> matches = f.read.scan(/news\./) #read all file contents and scan for
>> matches
>> } #file is automatically closed on block exit
>> #do something with matches...
>
> with :
> matches = []
> File.open(file,'r'){|f|
> matches = f.read.scan(/news\./) #read all file contents and scan
> for matches
> p matches.length
> p matches
>
> i got :
> 0
> []
>
>> But you need a correct RegExp, /news\./ will match 'news.' and the
>> 'xxx.yyy' will not be included in the results
>
> no prob for me and the regexp
>