[Solved] Regex: How to match instances of text, including spaces and new lines? [closed]


You’re asking to match any number of lines of text, followed by only 1 additional newline at the end, simply: ^(.+\n)+\n(?!\n) will do what you’d like.

Example here: https://regex101.com/r/Hy3buP/1

Explanation:

^                        - Assert position at start of string
 (.+\n)+                 - Match any positive number of lines of text ending in newline
        \n               - Match the next newline
          (?!\n)         - Do a negative lookahead to ascertain there are no more newlines.

3

solved Regex: How to match instances of text, including spaces and new lines? [closed]