louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.46k stars 1.03k forks source link

regex case insensitive not working? #671

Closed Tzmo closed 3 years ago

Tzmo commented 3 years ago

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' }
]
bi-tm commented 3 years ago

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

Tzmo commented 3 years ago

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