Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Qu: REGEXP (http://www.velocityreviews.com/forums/t901803-qu-regexp.html)

averroes 02-10-2007 06:48 PM

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.

Gunnar Hjalmarsson 02-10-2007 06:59 PM

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

Mirco Wahab 02-10-2007 07:05 PM

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.

averroes 02-10-2007 11:26 PM

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

Dr.Ruud 02-11-2007 12:15 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57