Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to substring the URL in Javascript

Hello all, 

I am stuck with the code to use substring in javascript to extract the part of URL. 

https://abc.com:9001/xyz/myrequest

I need to extract only /xyz

Thanks in advance.

Solved Solved
0 8 1,817
2 ACCEPTED SOLUTIONS

Change to "print" , as I said refer to Apigee javascript samples and make adjustments.

print(
"Original address: "+url_add)
print(break_address(url_add))

View solution in original post

Thank you everyone for your valuable time. Preferably I wanted to use only Javascript to reduce the redundancy of adding extra policies. I used the below script and it worked. 

const supplyUrl = "https://my.supplier/supplier/tariffSelectionG_E5449168?t=randomChars"
  if(supplyUrl.includes('?')) {
    const url = supplyUrl.split('?')
    if(url.length > 0) {
      const tariff = url[0].split('supplier/')
      console.log('tariff:', tariff[1])
    }
  }

 

View solution in original post

8 REPLIES 8