python - unicode 正则表达式匹配 - 如何搜索复选标记? ✓

标签 python regex python-3.x unicode

我正在尝试匹配其中包含复选标记的行:✓

我正在使用 python3。

unicode 编码可以在这里阅读:https://codepoints.net/U+2713?lang=en

我要匹配的行看起来像这样:

✓ Chrome on MAC - MySite.com - version-1

re.match("✓", line) 不起作用。 re.match("/u2713", line) 也不起作用。

如何确定是否包含✓?

---更新---

已解决:显然在 ✓ 之前有某种不可见的字符,这导致 match 运算符失败。感谢@NickT 和@EricDuminil 为我提供线索。此外,in 运算符似乎更简单、更安全,因此我将该答案标记为正确。

最佳答案

您甚至不需要任何正则表达式。你可以使用 in operator :

>>> "✓" in "✓ Chrome on MAC - MySite.com - version-1"
True
>>> "✓" in "Chrome on MAC - MySite.com - version-1"
False

如果你想在'marks.txt'中显示带复选标记的行,你可以这样写:

with open('marks.txt') as f:
    for line in f:
        if "✓" in line:
            print(line, end='')

关于python - unicode 正则表达式匹配 - 如何搜索复选标记? ✓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103373/

相关文章:

python - 无法使用 selenium 和 python 从 html 表中检索链接

regex - vim 中分隔符之间的数字递增

c# - 搜索字符串,用单词的副本替换单词的实例,并用 HTML 标签包围

python - 如何使用正则表达式提取第二个字符串(空格后)?

python - 如何识别缺失索引

algorithm - python中后缀算法的中缀

python - 将图像加载到 Dask Dataframe 中

python - Pandas 数据透视表 : Aggregate function by count of a particular string

python - 在 Django 中交叉导入

regex - 正则表达式匹配从 PostgreSQL 8.3 到 9.2 有什么变化?