[SERVER-28951] Regex returns partial matches Created: 25/Apr/17  Updated: 27/Oct/23  Resolved: 25/Apr/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Green Luo Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

See description

Participants:

 Description   
Original Summary

Regex matching failed when ":" is presented

Original Description

Here is my mongodb shell session

> db.foo.save({path: 'a:b'})
WriteResult({ "nInserted" : 1 })
> db.foo.findOne()
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
> db.foo.save({path: 'a:b:c'})
WriteResult({ "nInserted" : 1 })
> db.foo.find({path: /a:[^:]+/})
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
{ "_id" : ObjectId("58fedc57622e89329d123ee9"), "path" : "a:b:c" }
> db.foo.find({path: /a:[a-z]+/})
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
{ "_id" : ObjectId("58fedc57622e89329d123ee9"), "path" : "a:b:c" }

Clearly the regex /a:[^:]/ and /a:[a-z]/ shall not match string 'a:b:c', but looks like mongo failed on this regex



 Comments   
Comment by Kelsey Schubert [ 25/Apr/17 ]

Hi greenlaw110,

That's right, I've updated the ticket summary to clarify this behavior.

Kind regards,
Thomas

Comment by Green Luo [ 25/Apr/17 ]

Alright so according to http://stackoverflow.com/questions/43602310/mongdodb-regex-matching-failed-when-presented/43602744#43602744 it is due to partial matching, not a bug

Generated at Thu Feb 08 04:19:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.