javascript - Extract ip address from a string using regex -


 var r = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"; //http://www.regular-expressions.info/examples.html  var = "http://www.example.com/landing.aspx?referrer=10.11.12.13";  var t = a.match(r); //expecting ip address result gets null 

the above code extract ip address string. fails so. kindly advice fails.

you have defined r string, initialize 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 = "http://www.example.com/landing.aspx?referrer=10.11.12.13";    var t = a.match(r);  alert(t[0])


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -