How to get domain from a string using javascript regular expression

前端 未结 2 1708
离开以前
离开以前 2021-01-03 11:39

As the title suggests, I\'m trying to retrieve the domain from a string using javascript regular expression.

Take the following strings:

String              


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 12:28

    You can use this regex in Javascript:

    \b(?:(?:https?|ftp):\/\/)?([^\/\n]+)\/?
    

    RegEx Demo

提交回复
热议问题