From: Peter Bailey Date: 2007-09-19T00:27:31+09:00 Subject: Re: finding string matches, in order, in a file William James wrote: > On Sep 18, 8:28 am, Peter Bailey wrote: >> >> entry as one that's 300 lines deep into the file. In fact, the results >> look exactly the same to me. > > Don't give up yet. A regular expression is a very concentrated > piece of code, and it very often requires tweeking. > > Can you show us the first entry in the file that should > be matched? That would enable us to test our reg.exps. > > Some tricky points. A . won't match a newline unless > the m modifier is at the end of the regexp. > .* will often match too much unless you make it > non-greedy by appending ? (i.e., .*?). > Sometimes it's best to make the regexp case-insensitive > by using the i modifier. > You may assume that your text will always have > but perhaps it has > > Try this: > > %q{ > > > I'm Issue XIV, > who are you? > > > > I'm Issue XX, are you? > > > }.scan( > /\s*(.*?)<\/issue>/m){ > p $1 > } Believe me, I haven't given up. I need this to work! I really appreciate your perseverance, though. Here's what I have now: xmlfile.scan(/\s*(.*?)<\/issue>\n?/mi) do |match| codes = $1 puts codes end My xml file that I'm testing is 2087 lines deep. The first entry in this file is on lines 21-23. Here they are: Trade (Domestic & Foreign) So, these words, "Trade (Domestic & Foreign)" should be my first entry in my array. But, it continues to come up with the word "Immigration" as the first entry in the array, and that's way down on line 358. Thanks, Peter -- Posted via http://www.ruby-forum.com/.