![]() |
Qu: REGEXP
Hi,
i have some problem with a regexp. i have a string like this ';;;' with no quotes and i want subtitute it like this ';"";"";' my code is : my $string = ';;;' ; $string =~ s/;;/;"";/g ; print $string; but it prints ;"";; thank you for your help. Best regards. |
Re: Qu: REGEXP
averroes wrote:
> i have a string like this ';;;' with no quotes > and i want subtitute it like this ';"";"";' > > my code is : > > my $string = ';;;' ; > $string =~ s/;;/;"";/g ; > print $string; > > but it prints ;"";; Try: $string =~ s/;(?=;)/;""/g; Read about extended patterns in "perldoc perlre". -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
Re: Qu: REGEXP
averroes wrote:
> i have a string like this ';;;' with no quotes > and i want subtitute it like this ';"";"";' > > my code is : > > my $string = ';;;' ; > $string =~ s/;;/;"";/g ; > print $string; > but it prints ;"";; You're modifying pos($string) in a way that interferes with the pattern, so it won't work as intendet. You might use on of the following: my $string = ';;;'; 1) $string =~ s/;;/;"";/ while $string =~ /;;/; 2) $string =~ s/(?<=;)(?=;)/""/g; 3) $string = join '""', split '', $string; instead. Regards M. |
Re: Qu: REGEXP
Gunnar Hjalmarsson a écrit :
> averroes wrote: >> i have a string like this ';;;' with no quotes >> and i want subtitute it like this ';"";"";' >> >> my code is : >> >> my $string = ';;;' ; >> $string =~ s/;;/;"";/g ; >> print $string; >> >> but it prints ;"";; > > Try: > > $string =~ s/;(?=;)/;""/g; > > Read about extended patterns in "perldoc perlre". > Thank you, it's working And thanks for the advice, i'm reading the extended patterns. Best regards |
Re: REGEXP
averroes schreef:
> i have some problem with a regexp. > > i have a string like this ';;;' with no quotes > and i want subtitute it like this ';"";"";' > > my code is : > > my $string = ';;;' ; > $string =~ s/;;/;"";/g ; > print $string; > > > but it prints ;"";; > > thank you for your help. > > Best regards. You also posted this in news:alt.comp.lang.perl. You shouldn't multi-post. Use cross-posting, with the followup set to one of the groups, or even better: try one group, and only if that doesn't work out, try another. -- Affijn, Ruud "Gewoon is een tijger." |
| All times are GMT. The time now is 01:54 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.