RegEx for an IP Address

The [ shouldn’t be at the start of your pattern. Also, you probably want to use Matches(...).

Try:

String input = @"var product_pic_fn=;var firmware_ver="20.02.024";var wan_ip='92.75.120.206';if (parent.location.href != window.location.href)";
Regex ip = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
MatchCollection result = ip.Matches(input);
Console.WriteLine(result[0]); 

Leave a Comment