I want to match the URL host part with a regular express in JavaScript. Suppose I have a URL
var str = 'www.demo-site.com:1234'
and I designed below regular expression to match it
var regex = /^www\.demo-site\.com(:\d+)$/gi
As I expected, regex.test(str)
returns true
. However, if I run it again, it returns false. Why the results from running exactly the same function twice are different?
regex.test(str); //returns true
regex.test(str); //returns false