On Sun, 22 Oct 2006 10:02:37 +0900, Giles Bowkett wrote:

> Anybody know a way to make this DRYer?
> 
>     when /^([A-Za-z0-9,]+), '([^']+)', '([^']+)', '([^']+)'/
> 
> a literal regex with a subpattern repeated three times
> 
> I could probably split on the ', but it seems that might have unwanted
> side effects.
>

That's fine. I see no reason to make it more obfuscated. A couple tips
though:

 * Use .+? instead of [^']+
   .+? does a non-greedy match, which is what you're really trying to say
   with the [^']+

 * If you want to match the *same* text three times, for example 
   "a, '1', '1', '1'" but not "a, '1', '2', '3'", then you should use a
   backsubstitution in the match, using \2 twice, instead of the second
   two groups, so the pattern becomes
   /^([A-Za-z0-9,]+), '([^']+)', '\2', '\2'/

--Ken

-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
I've added a signing subkey to my GPG key. Please update your keyring.