help with regex matching multiple %e

MRAB python at mrabarnett.plus.com
Thu Mar 3 12:53:59 EST 2011


On 03/03/2011 17:33, mafunk at nmsu.edu wrote:
> Hi,
>
> i have a line that looks something like:
> 2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description
>
> I would like to extract all the numbers. From the python website i got the
> following expression for matching what in c is %e (i.e. scientific
> format):
> (see http://docs.python.org/library/re.html)
> [-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?
> And when i apply the pattern (using extra parenthesis around the whole
> expression) it does match the first number in the line.
>
> Is there any way to repeat this pattern to get me all the numbers in the
> line?
> I though the following might work, but i doesn't:
> ([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?){numToRepeat)
>
You're forgetting that the numbers are separated by a space.

> Or will i have to split the line first, then iterate and the apply the match?
>
> Any help is greatly appreciated.
>
Use re.findall to find all the matches.



More information about the Python-list mailing list