python - 准确匹配句子 4 次

标签 python regex

我有这个模式

    Calibration attempts: 0
    Successful calibrations: 0
    Calibration attempts: 0
    Successful calibrations: 0

我需要一个正则表达式来完全匹配它。这根本不应该匹配:

    Calibration attempts: 1
    Successful calibrations: 0
    Calibration attempts: 0
    Successful calibrations: 0

到目前为止我只想到了这个,但看起来很糟糕。

(.*Calibration attempts: 0\n.*Successful calibrations: 0\n.*Calibration attempts: 0\n.*Successful calibrations: 0.*)

最佳答案

这应该有效:(^[\t ]+(Calibration|Successful| |attempts|calibrations)+: 0$\n?){4}

查看regex101.com,您可以在那里进行测试。 我测试了这种情况,不匹配任何非“0”的内容

干杯。

关于python - 准确匹配句子 4 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61772012/

相关文章:

python - 在多个模块中重复相同的导入是否有问题?

javascript - 在 Django 中打印 PDF 文件

python - 在哪里添加 Pandas 的多索引级别?

python - 如何使用 tkinter 将按钮移出他的 parent ?

Python BeautifulSoup 从span标签获取数据

c# - RegEx.Replace 失败,替换字符串为 $0.00

javascript - 电话号码验证器

java - 使用java replaceAll方法用一个正则表达式替换句子中的单词

java - 使用正则表达式检查字符串是否以数字字符开头和结尾

regex - 仅当具有给定名称的 Docker 容器不存在时,如何执行 Bash 命令?