I have these strings:
baseUrl = "http://www.example.com"
baseUrl = "https://secure.example-server.com:443"
Can someone tell me how I can extract the server information from baseUrl so I can get either "example" and "example-server"
I have these strings:
baseUrl = "http://www.example.com"
baseUrl = "https://secure.example-server.com:443"
Can someone tell me how I can extract the server information from baseUrl so I can get either "example" and "example-server"
You can split strings at certain chars with split("."); (see http://www.w3schools.com/jsref/jsref_split.asp) then you can compare the results to your predefined words.
or you take the 2nd element of the results which would usually(?) be what you are looking for.
You can split it into an array with split() and extract the required one with slice() as follows:
baseUrl = "http://www.example.com"
baseUrl2 = "https://secure.example-server.com:443"
const base = baseUrl.split(".")
const base2 = baseUrl2.split(".")
console.log("Array1 :: ",base)
console.log("Array2 : ",base2)
console.log(base.slice(-2,-1))
console.log(base2.slice(-2,-1))
Array1 :: ["http://www","example","com"]
Array2 : ["https://secure","example-server","com:443"]
["example"]
["example-server"]