Christ That's certainly 1 way ;) -----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: 03 September 2007 16:11 To: Perl beginners Subject: Re: Regex help
Beginner wrote: > Hi, Hello, > I am trying to come up with a regex to squash multiple commas into > one. The line I am working on looks like this: > > SPEED OF LIGHT, , LIGHT SPEED,TRAVEL,TRAVELLING, , > DANGER,DANGEROUS,PHYSICAL, , CONCEPT,CONCEPTS, , , , , , , , , , > > There are instances of /,\s{1,},/ and /,,/ > > The bit that I am struggling with is finding a way to get a use a > multiplier for the regex /,\s+/ but I have to be careful not to remove > single entries. I guess the order of my substitutions is important > here. $ perl -le' $_ = q[SPEED OF LIGHT, , LIGHT SPEED,TRAVEL,TRAVELLING, , DANGER,DANGEROUS,PHYSICAL, , CONCEPT,CONCEPTS, , , , , , , , , , ]; > print; s/,\s*(?=,)//g; print; ' SPEED OF LIGHT, , LIGHT SPEED,TRAVEL,TRAVELLING, , DANGER,DANGEROUS,PHYSICAL, , CONCEPT,CONCEPTS, , , , , , , , , , SPEED OF LIGHT, LIGHT SPEED,TRAVEL,TRAVELLING, DANGER,DANGEROUS,PHYSICAL, CONCEPT,CONCEPTS, $ perl -le' $_ = q[SPEED OF LIGHT, , LIGHT SPEED,TRAVEL,TRAVELLING, , DANGER,DANGEROUS,PHYSICAL, , CONCEPT,CONCEPTS, , , , , , , , , , ]; print; $_ = join ",", grep /\S/, split /,/; print; ' SPEED OF LIGHT, , LIGHT SPEED,TRAVEL,TRAVELLING, , DANGER,DANGEROUS,PHYSICAL, , CONCEPT,CONCEPTS, , , , , , , , , , SPEED OF LIGHT, LIGHT SPEED,TRAVEL,TRAVELLING, DANGER,DANGEROUS,PHYSICAL, CONCEPT,CONCEPTS John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/