gpt4 book ai didi

javascript - 正则表达式在没有 www 的情况下不起作用

转载 作者:行者123 更新时间:2023-12-03 06:45:45 24 4
gpt4 key购买 nike

下面的正则表达式在没有 www 的情况下不起作用

 /((?:https?\:\/\/|www\.)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/i

我已检查以下网址

http://regexr.com       (working, match)
http://www.regexr.com/ (working, match)
www.regexr.com (working, match)
regexr.com (not working, should be match)
abc@gmail.com (working, not match)

如果我使用下面的代码

((?:https?\:\/\/|)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)

然后它也匹配电子邮件 ID

abc@gmail.com           (not working, should not match)

最佳答案

Demo on regexr.com

(https?:\/\/)?\w+(\.\w+)+(\/\w+)*(\/\w+\.\w+)?(\?[\w%&=.]*)*(?=[^\w.?&%=])

试试这个,

关于javascript - 正则表达式在没有 www 的情况下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37740579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com