var r = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"; //http://www.regular-expressions.info/examples.html
var a = "http://www.example.com/landing.aspx?referrer=10.11.12.13";
var t = a.match(r); //Expecting the ip address as a result but gets null
The above is my code to extract ip address from a string. But it fails to do so. Kindly advice where it fails.
// this is the regex to validate an IP address. = zeroTo255 + "\\." + zeroTo255 + "\\."
The regular expression for valid IP addresses is : ((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]?)
You have defined r
as string, initialize it as regular expression.
var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/; //http://www.regular-expressions.info/examples.html
var a = "http://www.example.com/landing.aspx?referrer=10.11.12.13";
var t = a.match(r);
console.log(t[0])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With