[Tutor] Regex puzzlement

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Aug 8 20:10:43 CEST 2004


My turn to be confused by a regex...

>>> import re
>>> r = re.compile('[&()-;:,.?!]')
>>> r.findall('Here is one, or two. but not 6 or 7')
[',', '.', '6', '7']
>>>

Why is it finding the numbers?
Presumably some weird regex convention amongst the chars I've 
put in the group, but what? And how do I get rid of it?

Alan G.



More information about the Tutor mailing list