JohnWick
JohnWick

Reputation: 5149

C# Regex Lazy Quantifier not matching expected values

Using the following input:

223.25.99.163</td>
<td ng-bind="proxy.PORT" class="ng-binding">1180</td>

This regex is failing to match

(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<\/td>.*?(\d{1,5})<\/td>

Upvotes: 1

Views: 42

Answers (2)

Thm Lee
Thm Lee

Reputation: 1236

You can also insert singleline(dot-all) modifier (?s) to the regex like this.

(?s)Your-regex

Upvotes: 1

wp78de
wp78de

Reputation: 18950

Your problem is most likely that the . does not match the newline.

Basically, you have two options: Replace the dot with a even broader match: [\s\S] is common:

(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<\/td>[\s\S]*?(\d{1,5})<\/td>

Demo1

Or you use the singleline/dot-matches-all regex option: RegexOptions.Singleline

Demo2

Upvotes: 2

Related Questions