Regex to extract subdomain from URL?

后端 未结 7 2475
名媛妹妹
名媛妹妹 2020-12-05 15:07

I have a bunch of domain names coming in like this:

http://subdomain.example.com (example.com is always example.com, but the subdomain varies).

I need \"subd

7条回答
  •  情话喂你
    2020-12-05 15:34

    To math sub domains with dot character in it, I used this one

    https?:\/\/?(?:([^*]+)\.)?domain\.com
    

    to get all matching characters after protocol until domain.

    https://sub.domain.com (sub)

    https://sub.sub.domain.com (sub.sub) ...

提交回复
热议问题