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.

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.