From: Harry Ohlsen Date: 2003-08-22T06:43:14+09:00 Subject: Re: Regular expression question This is a multi-part message in MIME format. --Boundary_(ID_Mbeub26IwuRohfGF9tGirw) Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT Xavier Noria wrote: >On Thursday 21 August 2003 13:23, dblack@superlink.net wrote: > > > >>Something like this (tweaked as needed) should work: >> >> irb(main):006:0> str >> => "\"Guido van Rossum\", \"Larry Wall\", \"Matz\"" >> irb(main):007:0> str.scan(/".+?"/) >> => ["\"Guido van Rossum\"", "\"Larry Wall\"", "\"Matz\""] >> >> > >Harry asked for support for \"s inside strings as well. For that a bit >more of work is needed: > > test = '>>"Guido", "Larry", "Matz", "foo \"bar\""<<' > puts test.scan(/"(?:\\.|[^"\\])*"/) > >gives > > "Guido" > "Larry" > "Matz" > "foo \"bar\"" > > > Thanks to both of you. I like that a lot better than the long one from MRE that Mike posted, but I guess I'll have to try some complex cases to see that it works 100%. Cheers, Harry O. --Boundary_(ID_Mbeub26IwuRohfGF9tGirw) Content-type: text/html; charset=us-ascii Content-transfer-encoding: 7BIT Xavier Noria wrote:
On Thursday 21 August 2003 13:23, dblack@superlink.net wrote:

  
Something like this (tweaked as needed) should work:

  irb(main):006:0> str
  => "\"Guido van Rossum\", \"Larry Wall\", \"Matz\""
  irb(main):007:0> str.scan(/".+?"/)
  => ["\"Guido van Rossum\"", "\"Larry Wall\"", "\"Matz\""]
    

Harry asked for support for \"s inside strings as well. For that a bit 
more of work is needed:

    test = '>>"Guido", "Larry", "Matz", "foo \"bar\""<<'
    puts test.scan(/"(?:\\.|[^"\\])*"/)

gives

    "Guido"
    "Larry"
    "Matz"
    "foo \"bar\""

  
Thanks to both of you.  I like that a lot better than the long one from MRE that Mike posted, but I guess I'll have to try some complex cases to see that it works 100%.

Cheers,

Harry O.


--Boundary_(ID_Mbeub26IwuRohfGF9tGirw)--