perl.beginners
[Top] [All Lists]

Re: Regex help

Subject: Re: Regex help
From: Rob Dixon
Date: Mon, 03 Sep 2007 17:44:23 +0100
Newsgroups: perl.beginners


Beginner wrote:

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.

Can anyone offer any tips please?

Hey Dermot.

I think just

 $text =~ s/,[,\s]+/,/g;

is all you need.

Rob


<Prev in Thread] Current Thread [Next in Thread>