Ras
Ras

Reputation: 628

Extract text with newline

I am using this pattern

const string ptnBodytext = @"<p>\s*(.+?)\s*</p>";

in order to extract the text within the <p> tags. It works fine except for those text with newline, e.g.:

<p>
    Lorem ipsum
    second line or
    third one?
</p>

How can I change the pattern in order to include newline, tabs and so on?

Upvotes: 1

Views: 84

Answers (2)

Jan
Jan

Reputation: 43169

You either need to activate the dotall mode or:

const string ptnBodytext = @"<p>([\s\S]+?)</p>";

See a demo on regex101.com.

Upvotes: 4

Dmitry Egorov
Dmitry Egorov

Reputation: 9650

Just remove the \s*:

const string ptnBodytext = @"<p>(.+?)</p>";

Upvotes: 2

Related Questions