basically I would like to check whether an URL starts with http/https or not. I am def. no expert in RegEx but I am kinda confused on why my approach is wrong.
RegExp constructor or wrap your Regular expression between two
And you can simplify your Regular expresion like so
^asserts position at start of the string
1st Capturing Group
httpmatches the characters http literally (case sensitive)
s?matches the character s literally (case sensitive) and
?Quantifier — Matches between zero and one times
This is a working Snippet:
var str = "https://regex101.com/"; alert(str.match(/^(https?)/));
str.match(/^(https?)/)will return an array containing all the matched strings.
gglobal modifier with your Regex: