Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will someone explain this javascript REGEX pattern?

src.match(/^(https?\:\/\/.*)\//)

I know regular expressions but the syntax is not familiar to me. Can somebody explain to me what it's matching?

like image 909
Uzair Farooq Avatar asked Feb 16 '26 13:02

Uzair Farooq


1 Answers

Matches anything that starts with http:// or https:// followed by any number of any character (.*), followed by another / slash.

The / slashes need to be escaped. I don't know why the colon is escaped too.

like image 73
mpen Avatar answered Feb 18 '26 03:02

mpen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!