From: "David A. Black" Date: 2008-05-01T23:55:20+09:00 Subject: Re: splitting with a regex & keeping a ref? Hi -- On Thu, 1 May 2008, Kyle Schmitt wrote: > I'm writing some scripts to help handle some ornery samba servers we > have: part of that is unfortunately reading the config scripts that > have built up over the years. > > I was hoping to use the standard string method as a quick & > not-so-dirty way of parsing the files, given that samba uses a very > simple format. > > #the sample_data variable is defined below > irb(main):sample_data.split(/\[[a-z0-9]+\]/i) > => ["", "\ncomment = shared directory for the shop\npath = > /dept/shop\nvalid u ....(truncated) > Gives good results, but omits what's between the brackets. I expected > that part. > > irb(main):sample_data.split(/(\[[a-z0-9]+\])/i) > => ["", "[shop]", "\ncomment = shared directory for the shop\npath = > /dept/sho ....(truncated) > Neat, gives me the data between the brackets in an element before the > data itself. > > > I know quite well I can zip through that array again, but I was > wondering, hoping, that there would be a way of accessing that back > reference in a block as part of the split. I'm afraid I can't quite follow that sentence. What do you mean by a back reference? Can you show some sample desired output? David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!