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

Re: [FWP] counting in REs



>>>>> "RM" == Rich Morin <rdm@cfcl.com> writes:

  RM> At 12:04 PM -0400 9/8/99, WORENKLEIN, David, GCM wrote:
  >> Hint: #3 is just as easy as #1 and #2.

  RM> Ahem.  This is _almost_ the approach I suggested; here's mine:

  RM>    $string =~       /^[^a]*(a[^a]*a)*[^a]*$/ &&
  RM>    $string =~       /^[^b]*b[^b]*(b[^b]*b)*[^b]*$/;

well, i ran into the same bug your first expression has. try it with
this input:

mamamama

it fails.

my version fixed that case by including the prefix non-a string in the
group. i also used non-grabbing parens to speed it up.


i just also realized that i read the problem wrong and b has an odd
number. my fix (same as rich's to get an odd number) is here:

/^[^b]*b(?:[^b]*b[^b]*b)*[^b]*$/

and as others have mentions that is not one expression but two. my
solution is one.

lookaheads are the way to go.

and i still have a bug which i was about to fix when i saw jeff pinyan's
working version which mine was approaching, i will leave this thread. i
have real work to do :-(

BTW the slow response time of this mail list server is annoying. 

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.

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