Search code examples
regexcarriage-return

regex expression any character with spaces and carriage returns


I would like to find an regex expression that contains any characters and any carriage returns:

Example . I would like to find the String from "Mytext.." to "EndofMyText"

Anytext
Mytextstartshere
        more text
        more text
EndofMyText
LastTet

my Problem is the carriage returns. What is the correct regex match expression ? :

I started with : Mytext(.*?[\r\n])EndofMyText


Solution

  • Maybe you could repeat this part one or more times (?:.*?[\r\n])+ and make it a non capturing group

    Mytext(?:.*?[\r\n])+EndofMyText

    or use [\s\S]+?

    Mytext[\s\S]+?EndofMyText

    When using a flag for dot matches newline, you could use Mytext.*?EndofMyText