David, back reference as in a regex back reference.
In a nutshell, it stores what was matched, and allows you to do
something with it.  You just place parentheses around the part of the
match you want to save.

They work like this in ruby's gsub (but a little differently in sed,
if that's the regex you grew up with).

example=%{Brian had a dog
James had a cat
Allen has a hampster}
puts example
#If you wanted to change the type of pet with gsub, you could do it like this...
puts example.gsub("/[^ ]+$/","grue")
#but if you wanted to describe the pet, and not change the type, you'd
need a backreference
puts example.gsub(/([^ ]+$)/){|i| "big ugly #{i}"}

On Thu, May 1, 2008 at 9:55 AM, David A. Black <dblack / rubypal.com> wrote:
> 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!
>
>