Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Qu: REGEXP

Reply
Thread Tools

Qu: REGEXP

 
 
averroes
Guest
Posts: n/a
 
      02-10-2007
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.
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-10-2007
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
 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      02-10-2007
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.
 
Reply With Quote
 
averroes
Guest
Posts: n/a
 
      02-10-2007
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
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      02-11-2007
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."

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matìj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:50 PM



Advertisments
 



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