Jquery To get substring from a long string within two specific sub strings

magento.stackexchange https://magento.stackexchange.com/questions/302587

  •  06-04-2021
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top