resp78
resp78

Reputation: 1534

How to match multiple lines using regex in C#

I am trying replace some content in a tex file, example bellow.

I would like to match the content from \starttable till second \HL.

\starttable[|lp(0.08\textwidth)|lp(0.35\textwidth)|lp(0.48\textwidth)|lp(0.08\textwidth)|]
\HL
\NC Req. Id
\NC Description
\NC Test Scenario
\NC Result
\NC\AR
\HL
\NC TAF-89

\NC Trigger test start - from jig

\NC 
\NC Unavailable

\NC\AR
\NC TAF-88

\NC Trigger test start - using scanner

\NC 
\NC Unavailable

\NC\AR
\HL

I tried with

Regex tableHeaderRegex = new Regex(@"(\\starttable(.*))(\\HL..(\\NC.*)+\\HL)",
                                 RegexOptions.Singleline);

But this does not stop at the second \HL, but goes on to match the last \HL because of \\NC.*

I have also tried the RegexOptions.Multiline but with no success.

Upvotes: 0

Views: 102

Answers (1)

vks
vks

Reputation: 67968

\\starttable[\s\S]*?\\HL[\s\S]*?\\HL

You can use this without g flag to attain the same.See demo.

https://regex101.com/r/vN3sH3/41

Upvotes: 1

Related Questions