javascript正则表达式

image.png
正则表达式:
(http(s)?:\/\/)?(www\.)?((.+?\.com)\/?(\?[^\?]+)?$|([^\s\:]+\.(net|cn|org|top|wiki|edu|gov)))(\/[^\s]*)*
输入字符串:
This is a url test olc check this url:chinadaily.com.cn/WS5eb90325a310a8b241154d2c.html. This is our dailu schedule government test connetion.This is a url test olc check this url:http://www.chinadaily.com.cn/a/202005/12/WS5eb90325a310a8b241154d2c.html. This is our dailu schedule government test connetion.
请问我不希望url结尾的.被匹配到,应该怎么修改这个正则?

阅读 1.8k
2 个回答

最后那里,排除内容中,加上不想要的:[^\s] => [^\s.]

\bhttps?:\/\/(?=\S*(?:net|cn|org|top|wiki|edu|gov|com))\S+\w
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题