开发者

How to catch group In regex which includes newLine?

开发者 https://www.devze.com 2023-04-02 12:44 出处:网络
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 开发者_如何学Pythonnot be included ) , please no

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 开发者_如何学Pythonnot 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


Use the following pattern:

@"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!

0

精彩评论

暂无评论...
验证码 换一张
取 消