python - 如何在 python 中比较 "hello:"=="hello"
问题描述
我想忽略字符串中的符号并与非符号字符串进行比较
name="Avengers Endgame"
find_element_by_link_text(name.title()).click()
<a href="#">Avengers: Endgame</a>
解决方案
您可以在单词类 ( )上使用正则表达式。\W
从链接,
\W Matches any character which is not a word character. This is the opposite of \w. If the ASCII flag is used this becomes the equivalent of [^a-zA-Z0-9_]. If the LOCALE flag is used, matches characters considered alphanumeric in the current locale and the underscore.
喜欢,
import re
a = 'Avengers Endgame'
b = 'Avengers: Endgame'
if re.sub(r'[\W]', '', a) == re.sub(r'[\W]', '', b):
print("They match")
推荐阅读
- amazon-web-services - 既然 Lightsail 有自己的防火墙,我们还应该在 AWS Lightsail Debian 实例中使用 ufw 吗?
- jmeter - jmeter cookie删除问题以编程方式
- mongodb - Mongo Db $not $in 带有多个键的查询
- javascript - 反转 x 和 y 轴谷歌图表
- java - Java:包含不同样式的更多 span 无法使用 OpenHtmlToPdf 转换为 PDF 格式
- python - Elasticsearch 并行批量更新或索引优先
- sql - 我无法添加外键
- mysql - Laravel 将阿拉伯语保存到 MYSQL 数据库中
- git - Git 不暂存子目录中的 .mp4 文件
- 2sxc - 如何获取与模块或项目的上次更改相关的用户信息