Michael Alipio schreef:

> #I have this string:
>
> my $string = 'vd=root,status=';
>
> #Now, I want to transform it into:
>
> 'vd=root;status='
>
> #That is replace the comma(,) between root and status with semicolon
> (;);
>
>
> $string =~ s/vd=\w+(,)/;/;
> print $string,"\n";
>
> #And it prints:
>
> ;status=
>
> Can you tell me why it has ate up vd= as well?
> And how to get around with it..

Because the "vd=\w+" is part of the search-string, it will be replaced.
The () around the comma don't do what you expect.

You can't make the "vd=\w+" a zero-width positive look-behind assertion
yet (see `perldoc perlre`) because the length of \w+ is not fixed. So
you need to capture that part:

  $string =~ s/\b(vd=\w+),/$1;/;

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to