How about...

#!/usr/bin/perl
use warnings;
$_ = "data: \"this is a string\" more: \"this is another\"";
s/(\w+)\s/$1 /g;
print "$_\n";

It prints:

data: "this is a string" more: "this is another"


On Tue, Jul 13, 2010 at 6:00 AM, Bryan R Harris <bryan_r_har...@raytheon.com
> wrote:

>
>
> I'm trying to temporarily deal with simple quoted strings by turning:
>
>  data: "this is a string" more: "this is another"
>
> into...
>
>  data: "this&nbsp;is&nbsp;a&nbsp;string" more: "this&nbsp;is&nbsp;another"
>
> I thought this would work:
>
>  s/(['"])([^\1]*)\1/${1}.despace($2).$1/gse;
>
>  sub despace {
>      my $t = shift;
>      $t =~ s/\s/&nbsp;/g;
>      return $t;
>  }
>
> ... but it doesn't.  It looks like the [^\1]* in the regex isn't working
> right.
>
> I can always split it into two, but I'm curious why the above doesn't work.
>
> TIA.
>
> - Bryan
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to