将句子精确匹配4次

2024-09-30 20:26:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个图案

    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.*)

Tags: 图案calibrationattemptssuccessfulcalibrations
1条回答
网友
1楼 · 发布于 2024-09-30 20:26:01

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

查看regex101.com,您可以在那里进行测试。 我测试了此案例是否不匹配任何不是“0”的内容

干杯

相关问题 更多 >