matching multiple regexs to a single line...

maney at pobox.com maney at pobox.com
Wed Nov 20 11:37:08 EST 2002


Alex Martelli <aleax at aleax.it> wrote:
> Alexander Sendzimir wrote:
>> # I will say that what I don't like about the approach you propose is that
>> # it throws information away. Functionally, it leads to brittle code which
>> # is hard to maintain and can lead to errors which are very hard to track
>> # down if one is not familiar with the implementation.
> 
> I suspect it would be possible to construct utteances with which I
> could disagree more thoroughly than I disagree with this one, but
> it would take some doing.  I think that, since re patterns support
> the | operator, making use of that operator "throws away" no 
> information whatsoever and hence introduces no brittleness.

Just to prove that someone else is reading this thread (barely)...  :-)

I can somewhat agree with Alexander, and I think you're overlooking the
way that this approach does force the regexps and their associated
handler code apart in the source code.  Most of his objections, yes,
they're misguided, but the loss of the simple nearness of the pattern
with the action is one legitimate complaint against the
all-in-one-regex approach to this.

Of course, the reason the Perl pattern he started with was so clean and
straightforward was due to a globally shared "result of last re
applied" state, wasn't it?  Talk about frangible design!  OTOH, it does
fall into line with doing things by sensible convnetion rather than
strict rules, which you say (elsewhere, not quoted in reply) is Pythonic...

> some more normal people following this thread...:-): if the

I refuse to admit that I am "normal", please.  :-)

> In some other cases client code may not only need to have no
> constraints against using groups in the RE patterns, but also
> want "the match-object" as an argument to the action code.  In

This is one point on which I agree with Alexander: it seems to me to be
the usual case that the regexp both identifies and parses the target. 
If it isn't being used in that dual mode, then the whole issue
addressed here (and in at least two other threads during the past week)
doesn't exist.




More information about the Python-list mailing list