如何在Python上匹配除下划线以外的所有字母数字 [英] How to match all alphanumeric except underscore on Python

查看:26
本文介绍了如何在Python上匹配除下划线以外的所有字母数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图用正则表达式匹配所有字母数字字符,下划线除外.我目前正在使用 r"^[a-zA-Z0-9]*",但我想知道是否可以使用 \w 并排除 _.

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 _.

谢谢!

推荐答案

是的,像这样:[^\W_]

其中 \W\w

这篇关于如何在Python上匹配除下划线以外的所有字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆