develooper Front page | perl.beginners | Postings from February 2009

Re: RegExp Problem using Substitutions.

Thread Previous | Thread Next
From:
John W. Krahn
Date:
February 24, 2009 03:44
Subject:
Re: RegExp Problem using Substitutions.
Message ID:
49A3DD90.2090505@shaw.ca
Deviloper wrote:
> Hi there!

Hello,

> I have a string "aaaabbbababbaaassass". I want to get a string without
> any double a 'aa' or and without the 'b's.
> 
> but if I do:
> 
> my $s = "aaaabbbababbaaassass";
> $s=~ s/aa|b//g;
> 
> as a result I will get a string "aaassass".
> 
> (I understand WHY I get this result. 
> But I donĀ“t know how to avoid this. (Using only one substition.))

I think you want something like this:

$s =~ s/[ab]*(?=a)|b+//g;



John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About