louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regex case insensitive not working?

Tzmo opened this issue · comments

i have the following code to try find an exact name with regex case insensitive and it sorta works but gives multiple responses instead of only returning the right one, any ideas on why it does this or how to fix?

Code:

Database.find({ thing: { $regex: /^roblox*$/i } }, function (err, docs) {
    console.log(docs);
});

Database:

{"thing":"ROBLOXf","_id":"Cq4VF4beqYL3hzV5"}
{"thing":"ROBLOXxx","_id":"IzMuNLoJX0bzIHir"}
{"thing":"ROBLOXe","_id":"O8OJEjnz2u0hiqvi"}
{"thing":"ROBLOX","_id":"ZS1dfQzmPXwpEh8W"}
{"thing":"ROBLOXxxx","_id":"cqQSgXs7nJAOiBt3"}
{"thing":"ROBLOXxxxxxxx","_id":"fYo61bqmcKWoHhNe"}
{"thing":"ROBLOXxxxx","_id":"pRUSpVpvobW0ihVG"}
{"thing":"ROBLOXs","_id":"uBAgjaG6fhuops9A"}

Response:

[
  { thing: 'ROBLOXxx', _id: 'IzMuNLoJX0bzIHir' },
  { thing: 'ROBLOX', _id: 'ZS1dfQzmPXwpEh8W' },
  { thing: 'ROBLOXxxx', _id: 'cqQSgXs7nJAOiBt3' },
  { thing: 'ROBLOXxxxxxxx', _id: 'fYo61bqmcKWoHhNe' },
  { thing: 'ROBLOXxxxx', _id: 'pRUSpVpvobW0ihVG' }
]

Hi,
in a regular expression X* means, that the letter X occurs 0,1, or more times. So the result is right.I like to use https://regex101.com/ for experimenting with regex. Perhaps you like to check the result there.
Kind regards
Torsten

ahh, my mistake then, thanks for the help @bi-tm