simple string parsing ?
Peter Kleiweg
in.aqua.scribis at nl.invalid
Thu Sep 9 11:39:20 EDT 2004
Peter Kleiweg schreef:
> 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)
Even simpler:
import re
R = re.compile('[=+*:()]|[^=+*:() \t\r\n]+')
s = '=+GC142*(GC94+0.5*sum(GC96:GC101))'
R.findall(s)
--
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