Hi Johnno--

You can use '+' in a regex to mean 'one-or-more', so
s/\|+/|/ would mean "replace one or more pipe with 
a single pipe" (you don't need to escape the pipe
in the replacement string).  

As a style matter, you can enclose the pipe in a
chacter class with []s to make it easier to read:
s/[|]+/|/

So your problem would look like:

perl -e '$string = q/1||||2||||3|4|||5/; $string =~ s/[|]+/|/g; print "$string\n"'
1|2|3|4|5

Run perldoc perlre to see an in-depth explaination of all this.

--Kester


> Hello All,
> 
> I have a string that has got
> 
>  1||||2||||3|4|||5 
> 
> What I need it in is
> 
> 1|2|3|4|5
> 
> I have tried 
> 
> $string =~ s/\||/\|/g;
> 
> and i get this as a result
> 
> |1|||||2|||||3||4||||5|
> 
> what am i doing wrong?
> 
> Mnay Thanks,
> 
> Johnno
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to