Michael,

You don't you need the line beginning and line termination in
s/(^|[^ ]) ([^ ]|$)/$1$2/g;

Would
s/([^ ]) ([^ ])/$1$2/g
be simpler?

Thanks,

Ahmed

----- Original Message ----- 
From: Michael Fowler 
To: Pedro A Reche Gallardo 
Cc: [EMAIL PROTECTED] 
Sent: Wednesday, November 28, 2001 11:40 AM
Subject: Re: deleting white spaces


On Wed, Nov 28, 2001 at 01:06:19PM -0500, Pedro A Reche Gallardo wrote:
> Hi all,  I would like to delete all single white spaces from a string
> without deleting concatenated white spaces. An example:
> $string= "I want to delete all this spaces, but              this"
> 
> The result would be:
> 
> $string = "Iwanttodeleteallthisspacesbut                        this"

Your example output doesn't match your description.  You say you want to
delete single spaces and nothing else, but your output doesn't show this.

Consider:
    input:  I want to delete all this spaces, but              this
    output: Iwanttodeleteallthisspacesbut                        this

You've deleted the comma, and you actually have more whitespace in the
output.


Assuming your description is more correct than your example output, and the
example output should be:

    Iwanttodeleteallthisspaces,but              this

Then I would suggest something like:

    $_ = "I want to delete all this spaces, but              this";
    s/(^|[^ ]) ([^ ]|$)/$1$2/g;

It seems there should be a simpler way, perhaps without the $1 $2
replacement, but that's the best I came up with.

    
Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to