I'm facing an issue with splitting a string into an array using a regex that doesn't seem to be working properly.
Here is my code:
<script type="text/javascript">
function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
</script>
<script type="text/javascript">
$(document).ready(function(){
var product= GetURLParameter("name");
var producttype=GetURLParameter("type");
var prod = product.replace(/%20/g," ");
var productname = prod.split('\\s+(?=\\d+M[LG])');
alert(productname[0]);
});
</script>
The input string I am using is "Calpol Plus 200MG
"
The expected output should be array[0] = "Calpol Plus"
and array[1] = "200MG"
The regex pattern I am using is \\s+(?=\\d+M[LG])