nday, April 05, 2004 7:46 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Some help with strings
Hello All,
I have a string that has got
123|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||45|
what am
-Original Message-
I have a string that has got
123|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||45|
---
Johnno,
I'll give you the two part answer:
1) Your regex matches on
: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Some help with strings
Hello All,
I have a string that has got
123|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||45|
what am i doing wrong?
Mnay Thanks,
Johnno
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:
Hi John,
You forgot at least a backslash,
$string =~ s/\|+/\|/g;
Should do the job.
HTH
George
___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
uting backslash
Try
This is what I think you want
$string =~ s/\|+/\|/g;
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Johnno
Sent: Monday, April 05, 2004 9:46 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Some help with strings
Hello All,
I have a
April 05, 2004 10:46 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Some help with strings
Hello All,
I have a string that has got
123|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||45|
what am i doing
Hello All,
I have a string that has got
123|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||45|
what am i doing wrong?
Mnay Thanks,
Johnno
___
Perl-Unix-Users ma