Regex to match URL

后端 未结 14 2424
耶瑟儿~
耶瑟儿~ 2020-11-22 09:41

I am using the following regex to match a URL:

$search  = \"/([\\S]+\\.(MUSEUM|TRAVEL|AERO|ARPA|ASIA|COOP|INFO|NAME|BIZ|CAT|COM|INT|JOBS|NET|ORG|PRO|TEL|AC|A         


        
14条回答
  •  一向
    一向 (楼主)
    2020-11-22 09:55

    Changing the end of the regex to (/\S*)?)$ should solve your problem.

    To explain what that is doing -

    • it is looking for / followed by some characters (not whitespace)
    • this match is optional, ? indicated 0 or 1 times
    • and finally it should be followed by a end of string (or change it to \b for matching on a word boundary).

提交回复
热议问题