Help with regular expression in python

Matt Funk matze999 at gmail.com
Fri Aug 19 11:20:16 EDT 2011


Hi,
thanks for the suggestion. I guess i had found another way around the
problem as well. But i really wanted to match the line exactly and i
wanted to know why it doesn't work. That is less for the purpose of
getting the thing to work but more because it greatly annoys me off that
i can't figure out why it doesn't work. I.e. why the expression is not
matches {32} times. I just don't get it.

anyway, thanks though
matt

On 8/19/2011 8:41 AM, Jason Friedman wrote:
>> Hi Josh,
>> thanks for the reply. I am no expert so please bear with me:
>> I thought that the {32} was supposed to match the previous expression 32
>> times?
>>
>> So how can i have all matches accessible to me?
> $ python
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> data
> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01
> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01
> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01
> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01
> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01
> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01
> 2.150000e+01 2.199000e+01 : (instance: 0)       :       some
> description'
>>>> import re
>>>> re.findall(r"\d\.\d+e\+\d+", data)
> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01',
> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01',
> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01',
> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01',
> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01',
> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01',
> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01',
> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01']




More information about the Python-list mailing list