----- Original Message -----
From: "Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]>
To: "Leon" <[EMAIL PROTECTED]>

> >(Q2)    How to do the following :-
> >           If there are 2 spaces, I wish to convert it into 1 &nbsp like
> >this =>&nbsp
> >           3 spaces into 2 &nbsp like this => &nbsp&nbsp
> >           4 spaces into 3 &nbsp like this => &nbsp&nbsp&nbsp
>
> I would do something like this:
>
>   s/ ( +)/'&nbsp;' x length($1)/g;
>
> That matches a space and then one or more spaces and stores the "one or
> more" part in $1.  The length of $1 is 1 less than the number of spaces
> found.

Many Thanks to Jeff, Gordon, Bompa & Members.

Jeff solution seems to fit what I want, however the expression s/ (
+)/'&nbsp;' x length($1)/g;
print the substitution text ==>  &nbsp; x length( ) <==  instead of its
values. Example below:-

@a = ("this is 1 space => \n",
           "this is 2 space =>  \n",
           "this is 3 space =>   \n",
           "this is 4 space =>    \n");

$a = join '',@a;
$a =~s/ ( +)/'&nbsp;' x length($1)/g;
print $a;

#results
this is 1 space =>
this is 2 space =>'&nbsp;' x length( )
this is 3 space =>'&nbsp;' x length(  )
this is 4 space =>'&nbsp;' x length(   )

# what must I do to this regex
# $a =~s/ ( +)/'&nbsp;' x length($1)/g;
# so that I could get the undermentioned results

this is 1 space =>
this is 2 space =>&nbsp;
this is 3 space =>&nbsp;&nbsp;
this is 4 space =>&nbsp;&nbsp;&nbsp;

Thanks.


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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

Reply via email to