I have a concatenating javascript string that I need to parse and match “&mediaID=334380” wherever it falls in the string. I need to be able to find “&mediaID=” and then write out the numbers that follow the = and have it end on “
This concatenating var will have only once instance of “&mediaID=334380” in it, but it may be in a different part of the string.
var vidPlyrVars = "vidPlayerSchool=" + vid_partner + "&vidPlayerWd=" + vid_width + "&vidPlayerHt=" + vid_height + "&";
vidPlyrVars += "vidURL=" + vid_url + "&imgURL=" + img_url + "&color_button_bkg=0d141a" + "&color_controls_bkg=0d141a" + "&mediaID=334380" + "&share_buttons=on" + "&vip_url=http://somesite.com/all/index.html" + "&";
vidPlyrVars += "vidTitle=" + escape("some title") + "&";
vidPlyrVars += "autoplay=off&autoplay_refresh=always&full_screen=on&ad_prerolls=off&";
vidPlyrVars += "list_type=none&";
I just need the numbers after &mediaID= no matter how many numbers there are. I have tried splitting, but it wont work since the &mediaID= may be in a different location in the string.
*Also. What if the mediaID may or may not have a _ before ID such as media_ID and mediaID. Is there a way to match for both in one regex?
Thank you.
Regular expressions is the way to go here.
Try this in your console:
Also, if you want the number separatedly, you can use
[0-9]+ means any number from 0 to 9, that occurs at least once. And if you wrap it in parentheses, it’ll store it in the response (which is an array, by the way).
Let me know if there’s any other doubt. Cheers!