From D

Alex Martelli aleax at mac.com
Tue Jul 31 11:52:26 EDT 2007


mensanator at aol.com <mensanator at aol.com> wrote:

> code files? What's the regular expression for
> locating a number with an arbitrary number of digits
> seperated into an arbitrary number of blocks of an
> arbitray number of digits with an arbitrary number
> of whitespace characters between each block?

For a decimal integer (or octal) number, I'd use something similar to:
    r'\d[\d\s]+'

This also gets trailing whitespace, but that shouldn't be much of a
problem in most practical cases.  Of course, just like today, it becomes
a bit hairier if you also want to find hex, oct (to be 0o777 in the
future), other future notations such as binary, floats, complex numbers,
&c:-) -- but the simple fact that a [\d\s] is accepted where today only
a \d would be, per se, would not contribute to that hair in any
significant way, it seems to me.


Alex



More information about the Python-list mailing list