need help of RE
tiissa
tiissa at nonfree.fr
Sun May 29 04:08:17 EDT 2005
cheng wrote:
> im sorry, my engilsh is not vell well,
That's alright, you could have been french. ;)
> the string not only contain '&' and '|' and it can be anyting
>
> i just want to split out the "whole word" inside the string
Look at the example for split function of re module in the doc [1].
In short:
>>> import re
>>> s="(word1 & (Word2|woRd3))"
>>> re.split("\W+",s)
['', 'word1', 'Word2', 'woRd3', '']
>>> [w.lower() for w in re.split("\W+",s) if w != '']
['word1', 'word2', 'word3']
>>>
[1]http://python.org/doc/lib/node114.html
More information about the Python-list
mailing list