Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion splitting with a regex & keeping a ref?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kyle Schmitt  
View profile  
 More options May 1 2008, 10:46 am
Newsgroups: comp.lang.ruby
From: Kyle Schmitt <kyleaschm...@gmail.com>
Date: Thu, 1 May 2008 09:46:38 -0500
Local: Thurs, May 1 2008 10:46 am
Subject: splitting with a regex & keeping a ref?
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.

Is there any way to do that that I'm just missing?

Thanks,
           Kyle

sample_data=%{[shop]
comment = shared directory for the shop
path = /dept/shop
valid users = @shop @admin
public = no
writable = yes
force group = shop
create mask = 0770
[bob]
comment = User files for bob
path = /users/bob
valid users = bob @admin
public = no
writable = yes
create mask = 0770}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.