Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想验证带有或不带有 http 的 url。我试过了 ^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*
^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*
但这是火柴http://google.com but not www.google.com。我也想要一个匹配 www.google.com 的正则表达式。
http://google.com but not www.google.com
谢谢
尝试使用^(https?://)?而不是开始您的正则表达式^http(s{0,1})://
^(https?://)?
^http(s{0,1})://
^(?:https?://)? ... the rest of your regex
?:
?
PS我不确定是否quantifier minification对英语为母语的人有意义,这是俄语的粗略翻译:)希望,如果我弄错了,有人能理解我的意思并可以解决我的问题。
quantifier minification