Match First Sequence in Regular Expression?

Roger L. Cauvin roger at deadspam.com
Thu Jan 26 11:51:51 EST 2006


"Alex Martelli" <aleax at mail.comcast.net> wrote in message 
news:1h9rhxf.vlrqwp1l99n66N%aleax at mail.comcast.net...
> Tim Chase <python.list at tim.thechases.com> wrote:
>
>> > Sorry for the confusion.  The correct pattern should reject
>> > all strings except those in which the first sequence of the
>> > letter 'a' that is followed by the letter 'b' has a length of
>> > exactly three.
...
...
> If a little more than just REs and matching was allowed, it would be
> reasonably easy, but I don't know how to fashion a RE r such that
> r.match(s) will succeed if and only if s meets those very precise and
> complicated specs.  That doesn't mean it just can't be done, just that I
> can't do it so far.  Perhaps the OP can tell us what constrains him to
> use r.match ONLY, rather than a little bit of logic around it, so we can
> see if we're trying to work in an artificially overconstrained domain?

Alex, you seem to grasp exactly what the requirements are in this case.  I 
of course don't *have* to use regular expressions only, but I'm working with 
an infrastructure that uses regexps in configuration files so that the code 
doesn't have to change to add or change patterns.  Before throwing up my 
hands and re-architecting, I wanted to see if regexps would handle the job 
(they have in every case but one).

-- 
Roger L. Cauvin
nospam_roger at cauvin.org (omit the "nospam_" part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com





More information about the Python-list mailing list