James Stroud wrote:
> Paul McGuire wrote:
> > <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >>Hello,
> >>
> >> I cannot figure out a way to find a regular expression that would
> >>match one and only one of these two strings:
> [clip]
> >>Any suggestion ? Thanks a bunch !
> >>Mathieu
> >>
> >
> > A pyparsing approach is not as terse as regexp's, but it's not terribly long
> > either.
>
> To second Paul's suggestion, usually, if the regex is not immediately
> obvious, its probably better to look into parsing modules, pyparsing
> being one of the most accessible modules (to me, anyways)--and well
> worth learning.

I would say that it's better, before leaping to the implementation, to
understand the problem. IOW, rough out the grammar first --- in the
current case, not very complicated at all; the way I looked at it there
are only two possible outcomes from the tokeniser (space and not-space)
and only three non-terminal symbols (word, sentence, paragraph) -- then
choose the implementation.

>
> However, in complicated applications, regex is usually still fun and
> valuable as an intellectual exercise.

Indeed. Better use of the mind and the CPU than distractions du jour
like pseudorubiku or whatever it's called :-)

Cheers,
John

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to