[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] counting in REs



Randal L. Schwartz wrote:
> 
> >>>>> "Rich" == Rich Morin <rdm@cfcl.com> writes:
> 
> Rich> A friend of mine recently presented me with three cases to match with
> Rich> a regular expression:
> 
> Rich>    1)  test for an even number of 'a's in a string
> 
> Rich>    2)  test for an odd  number of 'b's in a string
> 
> Rich>    3)  test for an even number of 'a's
> Rich>        and      an odd  number of 'b's in a string
> 
> Not tricky if you permit forward lookahead.
> 
> SPOILER GAP...






























> #1 = /^([^a]*a[^a]*a)[^a]*$/;
                       ^
> #2 = /^([^b]*b[^b]*b)[^b]*b[^b]*$/;
                       ^

i think you're missing a * at the marked spots.
--
Steve Lane <sml@zfx.com>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe