C# Regex find string between two strings with newLine

The name of the Multiline option is misleading, as is the one of the correct option - Singleline:

Regex r = new Regex("start(.*?)end", RegexOptions.Singleline);

From MSDN, RegexOptions Enumeration:

Singleline - Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n).

Include the RegexOptions.SingleLine which means that . matches everything, including \n

Regex r = new Regex("start(.*?)end", RegexOptions.Multiline | RegexOptions.SingleLine);

See http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx for more details.

Use Singleline instead of Multiline:

Regex r = new Regex("start(.*?)end", RegexOptions.Singleline);

BTW, RegexBuddy is your invaluable friend (No, I'm not connected whatsoever to the author, except for being a happy user).


  1. Douglas

    • 2015/6/28

    C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone 

  2. Judah

    • 2018/12/22

    News Citigroup Inc.C. Consumer-Service Stocks Have Underperformed. Why It's Their Time to Shine. The Price to Earnings (P/E) ratio, a key valuation measure, is calculated by dividing the stock's

  3. Jaxon

    • 2021/4/6

    C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on.

  4. Xzavier

    • 2015/9/12

    Citigroup, Inc. Common Stock (C) Stock Quotes - Nasdaq offers stock quotes & market activity data for US and global markets.

  5. Christopher

    • 2018/12/3

    learn-c.org is a free interactive C tutorial for people who want to learn C, fast.

  6. Williams

    • 2018/6/27

    Discover historical prices for C stock on Yahoo Finance. View daily, weekly or monthly format back to when Citigroup, Inc. stock was issued.

  7. Rene

    • 2019/12/18

    Amazon.com: C Programming Language, 2nd Edition: 8601410794231: Brian W. Kernighan, Dennis M. Ritchie: Books.

  8. Monti

    • 2020/6/3

    The Centers for Disease Control and Prevention (CDC) cannot attest to the accuracy of a non-federal website. Linking to a non-federal website does not constitute an endorsement by CDC or any of its employees of the sponsors or the information and products presented on the website. You will be

  9. Jimenez

    • 2020/5/29

    C is considered as a middle-level language because it supports the feature of both low-level and high-level languages. C language program is converted into 

  10. Cade

    • 2015/10/29

    c = a + b; Here, ‘+’ is the operator known as addition operator and ‘a’ and ‘b’ are operands. The addition operator tells the compiler to add both of the operands ‘a’ and ‘b’. C/C++ has many built-in operator types and they are classified as follows:

  11. Cade

    • 2020/6/23

    The best site for C and C++ programming. Popular, beginner-friendly C and C++ tutorials to help you become an expert!

  12. Ricci

    • 2020/7/26

    C. diff (also known as Clostridioides difficile or C. difficile) is a germ (bacterium) that causes severe diarrhea and colitis (an inflammation of the colon). It’s estimated to cause almost half a million infections in the United States each year. About 1 in 6 patients who get C. diff will get it again in the subsequent 2-8 weeks.

Comments are closed.

Recent Posts