Regular Expression to match both relative and absolute URLs

后端 未结 6 1229
自闭症患者
自闭症患者 2021-02-09 03:12

Anyone want to try their hand at coming up with a regex that matches both:

  • /foo/bar/baz.gif
  • /foo/bar/
  • http://www.foo.com/foo/bar

I

6条回答
  •  醉话见心
    2021-02-09 03:51

    (http:/)?(/[\w.]+)+/?
    

    matches these, but maybe you had stricter conditions in mind?

提交回复
热议问题