javascript - I can't do a regular expression -
i have variable: física in mongodb , have model attribute name educación física.
i make regular expression passing variable física not return me educación física if database had model name fisica or fisica or something, give yes.
i using nodejs, mongodb, javascript...
sorry english , thank much.
the things need are:
anchors:
^means "beginning of input" ,$means "end of input"case insensitivity:
iflag means "ignore whether things capitalized or not"
so:
var rex = /^fisica$/i; // ^ ^ ^ // | | +------ flag (ignore case) // +------+-------- anchors example:
if (rex.test(somestring)) { // matches... } re comment below:
how can put fisica variable? because fisica example, variable sends frontend backend
for that, you'd need regular expression constructor, regexp:
var rex = new regexp("^" + yourvariable + "$", "i"); if there characters in value in yourvariable special in regular expressions, need escaped backslash. this question , answers cover escaping regular expression. in case:
var rex = new regexp("^" + somequotingfunction(yourvariable) + "$", "i");
Comments
Post a Comment