simple string parsing ?

Peter Kleiweg in.aqua.scribis at nl.invalid
Thu Sep 9 10:55:09 EDT 2004


TAG schreef:

> if  I have :
>
> =+GC142*(GC94+0.5*sum(GC96:GC101))
>
> and I want to get :
>
> ['=', '+', 'GC142', '*', '(', 'GC94', '+', '0.5', '*', 'sum', '(',
> 'GC96', ':', 'GC101', ')', ')']
>
> how can I get this ??????

import re
R = re.compile('[=+*:()]|[a-z]+|[A-Z]+[0-9]+|[0-9]*\.[0-9]+|[0-9]+|[^ \t\r\n])
s = '=+GC142*(GC94+0.5*sum(GC96:GC101))'
R.findall(s)

The last choice of the regex is to catch any tokens not defined
(except for white space).



-- 
Peter Kleiweg  L:NL,af,da,de,en,ia,nds,no,sv,(fr,it)  S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html




More information about the Python-list mailing list