Search code examples
regexpcre

regex over maximum amount of lines


I have some regex that is matching lines I do not want included. I have tried to use a positive and negative lookahead but I couldn't quite understand it fully. Instead I was wondering if there was an option to only match over a max number of lines e.g. 4?

My partially working regex is:

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

The problem is it is including the first 7 lines, which I do not want to be included. I only want it to include lines 11-14 in the text below:

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

I hope this makes sense.


Solution

  • As per my comment, it seems you want to match both 'TLS 1.1 Cipher suites' and 'The server accepted' in a single "block". Therefor I was thinking to negate an literal asterisk:

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

    See the online demo

    Not sure what your intention is further down the line with the matched substring. A small note, if you want to match a literal dot, you need to escape it with a backslash.