From: Don Levan Date: 2007-06-28T11:44:17+09:00 Subject: More Regexp and file load problems Hi All, I am struggling here and would be most appreciative of any help. I have a regular expression problem I can't seem to figure my way out of. I had sent a similar request this morning, and gratefully received two emails from David Black and Axel Etzold. Unfortunately, I am still having difficulty. I am trying to extract the font name attribute out of the following xml (this is an excerpt of a larger file). The weird thing, is that my regular expression correctly matches the text if I use TextMate's regular expression 'find in project feature' and with the freeware Reggy regular expression test tool found on Google code. It also matches correctly, if I text against a subset of the xml being parsed. I.E., see this first example. #!/usr/bin/env ruby # # Created by Don Levan on 2007-06-26. # Copyright (c) 2007. All rights reserved. string = %q( Helvetica 9 256 #000000 ") regexp = Regexp.new(/^\s* (\w*)<\/Font-family>\s*$/) if string =~ regexp puts "#{$1}" end Result: Helvetica However, if I run this script, there is no result. #!/usr/bin/env ruby # # Created by Don Levan on 2007-06-26. # Copyright (c) 2007. All rights reserved. regexp = Regexp.new(/^\s* (\w*)<\/Font-family>\s*$/) file = File.new('/Users/donlevan/Desktop/DDRs/Apple Dealer Price List.xml') file.each do |line| if line =~ regexp puts "#{$1}" end end I have looked at Hiproct and XML simple, unfortunately I can not get TextMate configured correctly so I keep getting Loaderrors when I try to use ruby gems. Thanks, Don