简体   繁体   中英

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 !

eg : 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

使用以下模式:

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM