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
Post a Comment