On Fri, Jun 15, 2007 at 08:59:51AM +1000, Malcolm Tredinnick wrote: > > On Thu, 2007-06-14 at 18:24 -0400, Forest Bond wrote: > > On Thu, Jun 14, 2007 at 10:13:32PM -0000, SmileyChris wrote: > > > > What you want is "[-A-Za-z0-9_]+". > > > > > > > > The reason [-\w] doesn't work is because inside character classes > > > > ([...]), \w no longer means "alphanumeric characters". It's just a > > > > character escape. > > > > > > Alternately, make the string a "raw" one (note the r before the > > > quote): > > > r'[-\w]+' > > > > Not sure that's true. Malcolm was indicating that it is a character escape > > at > > the reg-exp level, not the Python string-parsing level. > > > > Character classes can't be merged in Python reg-exps. \w represents an > > entire > > character class, and, consequently, can't be merged with other classes by > > putting \w inside the new character class. > > Chris is right; I am clearly on drugs (again). > > In [6]: re.match(r'[-\w]+', '12-34-56').group() > Out[6]: '12-34-56' > > That was what I thought the answer was and then when I tested it before > making my reply it didn't work and the rationalisation seemed sound, so > I went with what worked. However, I must have made a typo when testing.
Oh. Didn't know that you could do that, and, as a result, assumed you were right. Sorry about that. -Forest
signature.asc
Description: Digital signature