I\'m trying to set a regexp which will check the start of a string, and if it contains either http:// or https:// it should match it.
How c
^ for start of the string pattern,
? for allowing 0 or 1 time repeat. ie., s? s can exist 1 time or no need to exist at all.
/ is a special character in regex so it needs to be escaped by a backslash \/
/^https?:\/\//.test('https://www.bbc.co.uk/sport/cricket'); // true
/^https?:\/\//.test('http://www.bbc.co.uk/sport/cricket'); // true
/^https?:\/\//.test('ftp://www.bbc.co.uk/sport/cricket'); // false