You really owe it to yourself to try the PyParsing package, if you have to do this kind of thing with any frequency.
The syntactic difference between PyParsing and regular expressions is greater than the syntactic difference between Python and C. thx Caleb On Tue, 19 Jul 2005 13:35:02 +0200, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > In a text that contains references to numbers like this: #583 I want to > find them with a regular expression but I'm having problems with the > hash. Hopefully this code explains where I'm stuck: > >>>> import re >>>> re.compile(r'\b(\d\d\d)\b').findall('#123 x (#234) or:#456 #6789') > ['123', '234', '456'] >>>> re.compile(r'\b(X\d\d\d)\b').findall('X123 x (X234) or:X456 X6789') > ['X123', 'X234', 'X456'] >>>> re.compile(r'\b(#\d\d\d)\b').findall('#123 x (#234) or:#456 #6789') > [] >>>> re.compile(r'\b(\#\d\d\d)\b').findall('#123 x (#234) or:#456 #6789') > [] > > As you can guess, I'm trying to find a hash followed by 3 digits word > bounded. As in the example above, it wouldn't have been a problem if > the prefix was an 'X' but that's not the case here. > -- http://mail.python.org/mailman/listinfo/python-list