locked
Find a string between 2 words including them RRS feed

  • Question

  • Hi,
     
    I have a multy line text. I am looking for a regex that will bring me the text between 2 given words including them.
    For example:  Rem start version 123 is the opening text, Rem end is the closing text. I want to replace the entire block including the Rem lines. 

    some text 1
    Rem start version 123
    some text 2
    some more text 3
    Rem end


    I need to find the text:

    Rem start version 123
    some text 2
    some more text 3
    Rem end

    Thanks
    Avi
    Wednesday, February 25, 2009 8:40 AM

All replies

  • Try this....

    string pattrn = @"Rem start[\s\S]*Rem end";

                string text = @"some text 1
    Rem start version 123 
    some text 2
    some more text 3
    Rem end";

                MatchCollection mc = Regex.Matches(text, pattrn);

                foreach (Match mat in mc)
                {

                    MessageBox.Show(mat.Value);

                }

    Hitesh
    Thursday, March 5, 2009 4:36 PM