how to avoid leading white spaces

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jun 4 20:44:16 EDT 2011


On Sat, 04 Jun 2011 09:39:24 -0400, Roy Smith wrote:

> To be sure, if you explore the edges of the regex syntax space, you can
> write non-portable expressions.  You don't even have to get very far out
> to the edge.  But, as you say, if you limit yourself to a subset, you
> can write portable ones.  I have a high level of confidence that I can
> execute:
> 
> ^foo/bar
> 
> on any regex engine in the world and have it match the same thing that
> 
> my_string.startswith('foo/bar')
> 
> does.

Not the best choice you could have made, for two reasons:

(1) ^ can match at the start of each line, not just the start of the 
string.  Although this doesn't occur by default in Python, do you know 
whether all other engines default the same way?

(2) There is at least one major regex engine that doesn't support ^ for 
start of string matching at all, namely the W3C XML Schema pattern 
matcher.

As you say... not very far out to the edges at all.


[...]
> As another example, a project I used to work on was very much into NIH
> (Not Invented Here).  They wrote their own pattern matching language,
> loosely based on snobol.  Customers signed up for three-day classes to
> come learn this language so they could use the product.  Ugh.

And you think that having customers sign up for a two-week class to learn 
regexes would be an improvement? *wink*

I don't know a lot about SNOBOL pattern matching, but I know that they're 
more powerful than regexes, and it seems to me that they're also easier 
to read and learn. I suspect that the programming world would have been 
much better off if SNOBOL pattern matching had won the popularity battle 
against regexes.



-- 
Steven



More information about the Python-list mailing list