python - 检查字符串是否包含python中的某些字符

标签 python

我想检查一个字符串是否只包含 A-Z 和 a-z 和 0-9 以及下划线和破折号 (_ -)

不应包含任何其他特殊符号,如 !"#\%

如何编写正则表达式?

并使用 match 或 ?

我的字符串如下所示:QOIWU_W QWLJ2-1

最佳答案

是的,re.match 似乎是一个很好的匹配(请原谅双关语)。至于正则表达式,像这样的东西怎么样:'[A-Za-z0-9-_]*'?

关于python - 检查字符串是否包含python中的某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8417488/

相关文章:

python - Pandas Apply 和 Loc - 效率和索引

python - 如何将标准输出转换为字符串 (Python)

Python OpenCV从字节字符串加载图像

python - 在复制其他列数据的同时拆分一列中的行中的值

python - Selenium:在 find_element_by_partial_link_text() 中使用多个字符串

python - 我如何将 numpy 数组转换为 pandas 数据框

python - 尝试从列表中删除时跳过的元素

python - 当输入的 dtype 为 uint8 时,tf.keras.Model.save 抛出 Not JSON Serialized

python - 数巴 0.35.0 : Use NumPy out parameter

python - 写一个位翻转算法