Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

 var r = "d{1,3}.d{1,3}.d{1,3}.d{1,3}"; //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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
612 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have defined r as string, initialize it as regular expression.

var r = /d{1,3}.d{1,3}.d{1,3}.d{1,3}/;

var r = /d{1,3}.d{1,3}.d{1,3}.d{1,3}/; //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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...