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!
Python has a special sequence \w for matching alphanumeric and underscore. Please note that this regex will return true in case if string has alphanumeric and underscore.
The _ (underscore) character in the regular expression means that the zone name must have an underscore immediately following the alphanumeric string matched by the preceding brackets. The . (period) matches any character (a wildcard).
For checking if a string consists only of alphanumerics using module regular expression or regex, we can call the re. match(regex, string) using the regex: "^[a-zA-Z0-9]+$".
Yes, like that: [^\W_]
Where \W
is the opposite of \w
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With