0

I have this variable:

var name = "Matemáticas"

And I would like to find in database, a model that it's name is either "Matemáticas" or "Matematicas" or "MATEMÁTICAS" or "MATEMATICAS" or "MatemátiCas" or "MatemaTicAs".

I try to do this:

var first_rg = name + '[a-zA-Záéíóú]'
var rg = new RegExp(first_rg, "g")
Theme.findOne({name: rg}, function(error, theme) {
}

But it doesn't work. I have not idea how to do this.

Thank you

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
oihi08
  • 737
  • 1
  • 6
  • 20
  • 6
    You should tell us what ORM you're using. – jessegavin Sep 17 '15 at 15:12
  • 2
    Why would appending `[a-zA-Záéíóú]` to the name create a regex that ignores characters **in** the name? The regex `Foo[a-zA-Záéíóú]` still requires that the string start with `Foo`. (Also, if you're using the `i` flag, the `A-Z` part of your character class [or the `a-z` part, take your pick] is redundant.) – T.J. Crowder Sep 17 '15 at 15:14
  • I added it because I think it is correct. I am using mongodb and node – oihi08 Sep 17 '15 at 15:15
  • `gi` = global, case-insensitive... – Marc B Sep 17 '15 at 15:18
  • If you are using MySQL you most likely don't need to do anything with the parameter as MySQL performs case-insensitive searches. Not too sure about the non-ascii characters, however. – HeadCode Sep 17 '15 at 15:52
  • 1
    If you're comparing in JavaScript, take a look at this post http://stackoverflow.com/questions/227950/programatic-accent-reduction-in-javascript-aka-text-normalization-or-unaccentin For SQL, check http://stackoverflow.com/q/14962419/5290909 – Mariano Sep 17 '15 at 16:06

0 Answers0