Royi Namir
Royi Namir

Reputation: 148524

How to catch group In regex which includes newLine?

I have that kind of paragraph , and i need to catch into group the INSIDE CONTENT !

e.g. : I need to cathe ANYTHING between AAA and BBB ( AAA,BBB should not be included ) , please notice new lines , \t \r \n between AAA and BBB

 AAA
          I Love You  /// can be any charcter + specials !!

    BBB

expected output : matches[0].Groups[1].ToString() ===> I Love You

Upvotes: 0

Views: 241

Answers (2)

Seffix
Seffix

Reputation: 1049

If you know for sure that the two string are there in that order and apear only once (you can check this), you can use the String.split() method.

    String[] seperators={"AAA","BBB"};
    String[] contents=paragraph.split(seperators, StringSplitOptions.None);
    String content=contents[1]; //the content between the two seperator strings

good luck!

Upvotes: 1

Paul Walls
Paul Walls

Reputation: 6044

Use the following pattern:

@"AAA([\s\S]+)BBB"

Upvotes: 2

Related Questions