From: Peter Bailey Date: 2007-09-19T21:03:13+09:00 Subject: Re: finding string matches, in order, in a file William James wrote: > On Sep 18, 1:26 pm, Peter Bailey wrote: >> > If this still won't work on your file, could the file >> > be contaminated with some non-displaying characters >> > that appear to be whitespace but aren't? >> > Perhaps this would be worth a try: >> > /[^<>]*(.*?)<\/issue>/m >> >> Still no go, William. I tried your last phrase there, too. > > You've got to track down what's going on. > Copy and paste the code below into a file. > (Don't even think about typing it in.) > Run the file. Is this the output? > > "\nI'm Issue XIV,\nwho are you?\n" > "\nI'm Issue XX, are you?\n" > "Trade (Domestic & Foreign)" > > If it is, open both the Ruby file and the xml > file with the same editor; copy the first desired > entry from the xml file and paste it at the bottom > of the big string in the Ruby file. Even though > it looks like an exact duplicate of what's already > in the string, maybe it differs somehow. > The output should now be: > > "\nI'm Issue XIV,\nwho are you?\n" > "\nI'm Issue XX, are you?\n" > "Trade (Domestic & Foreign)" > "Trade (Domestic & Foreign)" > > If it isn't, edit the entry that you just pasted > into the big Ruby string; delete spaces and > line-endings and replace them with new spaces and > line-endings. (Perhaps the the xml file has some > bizarre invisible characters.) > > %q{ > > > I'm Issue XIV, > who are you? > > > > I'm Issue XX, are you? > > > > Trade (Domestic & Foreign) > > > > }.scan( > # Using extended-mode regular expression for clarity. > # Whitespace and comments are ignored. > %r{ > > \s* > > (.*?) > > }xmi > ){ p $1 } I'm getting exactly what you predict. And, . . ., perhaps I haven't made this clear, but, I am getting healthy output from my script. I'm getting 208 lines of data. Each line is an entry between the entries I've described. They're just totally out of order! That's my problem. Here are the first 5 entries I get back: Immigration Health Issues Copyright/Patent/Trademark Budget/Appropriations Health Issues ... -- Posted via http://www.ruby-forum.com/.