超过最大行数的正则表达式

regex over maximum amount of lines

我有一些正则表达式匹配我不想包含的行。我曾尝试使用正面和负面的前瞻,但我无法完全理解它。相反,我想知道是否有一个选项可以只匹配最大行数,例如4?

我部分工作的正则表达式是:

TLS 1.1 Cipher suites(?s).*?The server accepted

问题是它包含了我不想包含的前 7 行。我只希望它在下面的文本中包含第 11-14 行:

 * TLS 1.1 Cipher suites:
     Attempted to connect using 80 cipher suites; the server rejected all cipher suites.

 * TLS 1.2 Cipher suites:
     Attempted to connect using 158 cipher suites.

     The server accepted the following 4 cipher suites:
        TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384             256       ECDH: prime256v1 (256 bits)

 * TLS 1.1 Cipher suites:
     Attempted to connect using 15 cipher suites.

     The server accepted the following 2 cipher suites:
        TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA                256       ECDH: prime256v1 (256 bits)

我希望这是有道理的。

根据我的评论,您似乎想在一个“块”中同时匹配 'TLS 1.1 Cipher suites' 和 'The server accepted'。因此我想否定一个文字星号:

TLS 1\.1 Cipher suites[^*]*The server accepted

在线查看demo

不确定您的意图是在匹配子字符串的后面。小提示,如果要匹配字面点,需要用反斜杠转义。