Splitting with Regular Expressions

qwweeeit qwweeeit at yahoo.it
Thu Mar 17 09:51:19 EST 2005


Splitting with RE has (for me!) misterious behaviour!

I want to get the words from this string:
s= 'This+(that)= a.string!!!'

in a list like that ['This', 'that', 'a.string']
considering "a.string" as a word.

Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s= 'This+(that)= a.string!!!'
>>> import re
>>> p=re.compile('[\W].')
>>> p.split(s)
['This', 'that', '', '', 'tring', '!']

>>> p=re.compile('[\W.]')
>>> p.split(s)
['This', '', 'that', '', '', 'a', 'string', '', '', '']

Help!



More information about the Python-list mailing list