Url regular expression

see a url regular expression on the Internet:

(https?|ftp|file)://[-A-Za-z0-9+&@-sharp/%?=~_|!:,.;]+[-A-Za-z0-9+&@-sharp/%=~_|]
The expression

must start with http: , and
if you don"t need http:, you can also . How can I modify it? The following
/ / www.baidu.com

Mar.13,2021

? means that the previous content matches 0 or 1 times. Add ? after (https? | ftp | file): ) to indicate that the previous content can appear 0 times or 1 times, that is to say, there can be protocols or no protocols in url .

(?:(https?|ftp|file):)?//[-A-Za-z0-9+&@-sharp/%?=~_|!:,.;]+[-A-Za-z0-9+&@-sharp/%=~_|]

I don't know if you use it in js. If you use it in js, these two / / need to be escaped:

let reg = /(?:(https?|ftp|file):)?\/\/[-A-Za-z0-9+&@-sharp/%?=~_|!:,.;]+[-A-Za-z0-9+&@-sharp/%=~_|]/

-sharp | http
(https?|http|ftp|file)
Menu