Here's kind of a dumb way to do it, but it might give you some ideas: ################# data = '"one" "1" " 0.1234" "0" "4"' puts data
string1 = data =~ /\d"$/ puts $& val1 = $&[0..0] string2 = data =~ /\d"\s+"\d"$/ puts $& val2 = $&[0..0] puts puts val1 puts val2 ############################################# On 3/15/07, Paul Carvalho <[EMAIL PROTECTED]> wrote: > Hi there. After several hours of looking at this problem, I've decided to > ask for some help. > > Here's the problem: I have an input text file that has a series of values > stored like this: > "one" "1" " 0.1234" "0" "4" > "two" "3" "1.3333" "1" "0" > ... > > I want the values in the 4th and 5th quotes on each line. I originally > thought about dumping each line 'split' into an array and working with the > array, but then I thought it might save me time if I could just figure out > the regular expression to get the right values. > > I've read through an online Regular Expression tutorial, reviewed a few > books, and downloaded two apps (PowerGREP and Regexile) to help me try and > figure this out but so far no luck. > > Here's the line I started with: > line =~ > /^\"[^"]*"\t\"[^"]*"\t\"[^"]*"\t\"([^"]*)"\t\"([^"]*)"\t/ > > => Expect $1 and $2 to hold the values I want... the (bracketed) regex's > > - I tried switching the \t with \s but no luck > - tried adding and removing extra backslashes around the quotes, but nothing > - tried adding and removing all sorts of other characters but still can't > get it to work. > > Can anyone help me figure out how to parse these input lines in a quick and > efficient way? I wanted to avoid having to rely on arrays, but I'm ready to > give up and use them right about now. > > Please let me know. Thanks in advance. Paul C. > > (P.S. the *actual* input file has something like 20 values on each line. If > I can figure out the pattern above for the simplified input file, I'm sure I > can apply it to the larger real input file.) > > > _______________________________________________ > Wtr-general mailing list > [email protected] > http://rubyforge.org/mailman/listinfo/wtr-general > _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
