7tags
7tags

Reputation: 13

Regex doesn't work

Hi guys I have next text:

</form>onclick="g(null,null,'.htaccess','touch')">Touch</a> <br><br><pre class=ml1>
DirectoryIndex index.php
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</pre></div>

I try to parse all between <pre class=ml1> and </pre></div> with: -

string con = Regex.Match(content, @"<br><br><pre class=ml1>(.*?)</pre></div>", RegexOptions.Multiline).Groups[1].Value;`

But it doesn't work. Why?

Upvotes: 0

Views: 188

Answers (2)

Parimal Raj
Parimal Raj

Reputation: 20575

The Only problem with your code is you have used Regex.MultiLine which should have been Regex.SingleLine

string con = Regex.Match(content, "<br><br><pre class=ml1>(.*?)</pre></div>", RegexOptions.Singleline).Groups[1].Value;

RegexOptions.MultiLine

Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string.

RegexOptions.SingleLine

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

Upvotes: 0

MikeM
MikeM

Reputation: 13631

You need

RegexOptions.Singleline

so the . matches every character including newlines.

You don't need RegexOptions.Multiline as you're not using ^ or $. (Multiline mode makes them match the beginning and end of a line, instead of the beginning and end of the input string.)

Upvotes: 1

Related Questions