nilsonneto
nilsonneto

Reputation: 495

How to match all alphanumeric except underscore on Python

I've been trying to match with regex all alphanumeric characters, except for the underscore. I'm currently using r"^[a-zA-Z0-9]*", but I wondered if it was possible to use \w and exclude _.

Thanks!

Upvotes: 15

Views: 6111

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89584

Yes, like that: [^\W_]

Where \W is the opposite of \w

Upvotes: 22

Related Questions