Question

I have a long string as - " https://example.com/js-form-name-62682.html?ref=https%3A%2F%2Fstaging.example.com%2sample%3Fsku%3D40567&referrer=embeddedtype-and-somemortext "

I want to get the value 40567 i.e the test which comes up withing sku%3D and &_referrer with jquery.

How can I get this ?

Please provide a solution.

Was it helpful?

Solution

I found the solution,

var MainString = "https://example.com/js-form-name-62682.html?ref=https%3A%2F%2Fstaging.example.com%2sample%3Fsku%3D40567&referrer=embeddedtype-and-somemortext";

var subStringVal = MainString.substring( MainString.lastIndexOf("3D") + 2, MainString.lastIndexOf("&_referrer") );

It gives - 40567

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top