[Tutor] help with regular expressions

janos.juhasz at VELUX.com janos.juhasz at VELUX.com
Thu Jul 1 01:59:51 EDT 2004


Hi Jeff,

>At 10:29 PM 6/29/2004, Jeff Peery wrote:
>>hello I am having trouble with using the re module. I have a statement:
>>
>>line = FileHandle.readline(-1)
>>test = findall('\d', line)
>>
>>where "line" is a line of text from a file I would like to read and
>>extract numbers from. the line is simply three numbers, example
>>3.444456    4   84.3546354.  I want to put these number in "test" but 
the
>>findall expression seems to only take whole numbers, so for example test
>>would be for the above numbers [3, 4, 4, 4, 4, 5, 6, 4, 8, ....].  How 
is
>>this done so that test = [3.444456    4   84.3546354]?
>
>
>>>> re.findall(r'\d+.?\d*', '3.444456    4   84.3546354')
>['3.444456', '4 ', '84.3546354']


I fell that, you are looking for this:

>>> re.findall('\S+', '3.444456    4   84.3546354')
['3.444456', '4', '84.3546354']


Yours sincerely, 
János Juhász 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040701/01d0f804/attachment.html


More information about the Tutor mailing list