howto combine regex special sequences?

Graham Guttocks graham_guttocks at yahoo.co.nz
Wed Oct 24 20:01:22 EDT 2001


Greetings,

I'm trying to compile a regex so that I can test whether a string
contains characters other than alphanumeric or whitespace.

I'm currently using this which seems to work:

  regex = re.compile(r'[^a-zA-Z0-9_ \t\n\r\f\v]')

I'd like to use the special sequences "\W" and "\S" for brevity
however.  How can I rewrite the above regex using them instead?

I thought the following would work, but it doesn't:

  regex = re.compile(r'\W\S')

Another question: is there an easier/faster way to test whether a
string contains characters other than alphanumeric or whitespace
without using the re module, or am I on the right track?

Regards,
Graham


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com




More information about the Python-list mailing list