Is it possible in JavaScript
to do something like preg_match
does in PHP
?
I would like to be able to get two numbers from str
get matched string back or false
function preg_match (regex, str) {
if (new RegExp(regex).test(str)){
return regex.exec(str);
}
return false;
}
var text = 'price[5][68]';
var regex = /price\[(\d+)\]\[(\d+)\]/gi;
match = regex.exec(text);
match[1] and match[2] will contain the numbers you're looking for.