The Regex Story

Lie Ryan lie.1296 at gmail.com
Thu Apr 8 17:24:34 EDT 2010


On 4/9/10, Tim Chase <python.list at tim.thechases.com> wrote:
> Lie Ryan wrote:
>> Why am I seeing a lot of this pattern lately:
>>
>> OP: Got problem with string
>> +- A: Suggested a regex-based solution
>>    +- B: Quoted "Some people ... regex ... two problems."
>>
>> or
>>
>> OP: Writes some regex, found problem
>> +- A: Quoted "Some people ... regex ... two problems."
>>    +- B: Supplied regex-based solution, clean one
>>       +- A: Suggested PyParsing (or similar)
>
> There's a spectrum of parsing solutions:
>
<snip>
>
> The above dialog tends to appear when the task isn't in the
> sweet-spot of regexps.  Either it's sufficiently simple that
> simple split/slice notation will do, or (at the other end of the
> spectrum) the effort to get it working with a regexp is hairy and
> convoluted, worthy of a more readable solution implemented with
> pyparsing.  The problem comes from people thinking that regexps
> are the right solution to *every* problem...often demonstrated by
> the OP writing "how do I write a regexp to solve this
> <non-regexp-optimal> problem" assuming regexps are the right tool
> for everything.
>
> There are some problem-classes for which regexps are the *right*
> solution, and I don't see as much of your example dialog in those
> cases.

I would have agreed with you if someone were to make the statement
until a few weeks ago; somehow in the last week or so, the mood about
regex seems to has shifted to "regex is not suitable for anything"
type of mood. As soon as someone (OP or not) proposed a regex
solution, someone else would retort with don't use regex use
string-builtins or pyparsing. It appears that the group has developed
some sense of regexphobia; some people pushes using string builtins
for moderately complex requirement and suggested pyparsing for not-so
complex need and that keeps shrinking regex sweet spot. But that's
just my inherently subjective observation.



More information about the Python-list mailing list