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.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to