i get an strange error “invalid quantifer” … can somebody help me please?
html
<input type="text" value="5+5" id="test"/>
JS
ups = {};
ups['2'] = new Array();
ups['2']['cmd'] = '#(\-|\+|\*|\/|)[0-9](,|[0-9]|)(\-|\+|\*|\/)[0-9]#gi';
var inp_val = $('#test').val();
if (inp_val.match(ups['2']['cmd']))
{
$('body').append('<br />OK');
}
In Javascript, Regular expressions should be written as
i.e.
moreover, it can be simplified as
The reason for the invalid quantifier is that, unlike PHP, a
\followed by an unrecognized character will result in that character without the\:'\p\q' == 'pq''\p\q' == '\\p\\q'Therefore, your string will be interpreted as
which is an invalid regex since the
+(a quantifier) is not preceded by any patterns.