Qu: REGEXP

A

averroes

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.
 
G

Gunnar Hjalmarsson

averroes said:
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".
 
M

Mirco Wahab

averroes said:
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.
 
A

averroes

Gunnar Hjalmarsson a écrit :
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
 
D

Dr.Ruud

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
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top