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

Re: [FWP] counting in REs



On Wed, Sep 08, 1999 at 10:17:33AM -0700, Rich Morin wrote:
> At 12:43 PM -0400 9/8/99, Ronald J Kimball wrote:
> >That fails on the same string I presented for David's regex:
> >'--a--a--a--a--' because it requires adjacent 'a's.
> >
> >    $string =~       /^[^a]*(a[^a]*a[^a]*)*$/ &&
> >    $string =~ /^[^b]*b[^b]*(b[^b]*b[^b]*)*$/
> 
> No, it doesn't.  For instance, it passes ' a b a ' just fine.

Yes, it does; it requires adjacent 'a's if there are more than 2 'a's.
The second and third 'a' must be adjacent, the fourth and fifth 'a', etc.


> OTOH, your test string ('--a--a--a--a--') does not meet the criteria
> for the question, as it does not contain an odd number of 'b's.

My test string was a test string just for the first regex; i.e. for task
#1.  If you're using separate regexes, then solving task #1 is a necessary
condition for solving task #3.


> -r
> 
> P.S.  To help us all read from the same page, here is a simple test
>        harness I hacked up:

Using the corrected regexes.  ;)

Ronald

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