how to split any url and get only source?

I want to split this type of Url.

Want to get abcnews

I used:


I get error can not split.

Any idea how to do it?

7 thoughts on “how to split any url and get only source?”

  1. Do you accept Regex response?

    const url=''
    let subdomain = url.match(/(\w*)\./)[1]
    // subdomain = "abcnews"

    With that, you get the word before the first dot.

    I think you get an error after:
    Because you have no "www", then the length of the array is 1 (array[0] only).


Leave a Comment