I try to extract the value (IP Address) of the wan_ip with this sourcecode: Whats wrong?! I´m sure that the RegEx pattern is correct.
String input = @\"var p
Regex.IsMatch(input, @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$")
If you just want check correct IP use IPAddress.TryParse
using System.Net;
bool isIP(string host)
{
IPAddress ip;
return IPAddress.TryParse(host, out ip);
}
Very old post, you should use the accepted solution, but consider using the right RegEx for an IPV4 adress :
((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
If you want to avoid special caracters after or before you can use :
^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
(\d{1,3}\.){3}(\d{1,3})[^\d\.]
Check this. It should work perfectly
Regex(@"\A\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\z") try with this
In Python:
>>> ip_regex = r'^{0}\.{0}\.{0}\.{0}$'.format(r'(25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)')
>>> match(ip_regex, '10.11.12.13')
<re.Match object; span=(0, 11), match='10.11.12.13'>
>>> _.groups()
('10', '11', '12', '13')
>>>