[SERVER-2943] dotall flag 's' from PCRE is not supported Created: 13/Apr/11  Updated: 12/Jul/16  Resolved: 14/Apr/11

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.8.0, 1.8.1
Fix Version/s: 1.9.0

Type: Bug Priority: Trivial - P5
Reporter: Charles-Henri d'Adhémar Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: regex
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Attachments: Text File dotall.patch    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

MongoDb does not support the dotall 's' flag from Perl Compatible Regular Expressions.
This flag makes the '.' dot character match really all characters including the newline character '\n'.

Example in pseudo code :

t = "foo\nbar\nnil"
r = "foo.*nil"
r.match(t, 's') => false;

If the dotall 's' flag was supported then the regular expression would match.
There is a workaround for this : Instead of using the dot character in the regex we can use the [\s\S] pattern :

r = "foo[\s\S]*nil"
r.match(t, 's') => true;

Since the documentation mention that MongoDB supports PCRE I consider this as a bug, none critical since a workaround exists.
One could consider this as a feature request, I have no issue with that

The bug is trivial to fix. See attached patch below. However the patch does not solve potential issues with other drivers such the javascript shell.
Indeed Javascript does not support the 's' flag ...

Since this is my first contact with the MongoDb community I would like to take the opportunity to thank you all for the amazing work around MongoDb

Cheers,
CH



 Comments   
Comment by Charles-Henri d'Adhémar [ 15/Apr/11 ]

Ok, a big thank you for your support !

Comment by Mathias Stearn [ 15/Apr/11 ]

It looks like the python driver will do the right thing when you
specify the DOTALL option to compiled regex objects.

On Fri, Apr 15, 2011 at 3:27 AM, Charles-Henri d'Adhemar (JIRA)

Comment by Mathias Stearn [ 15/Apr/11 ]

It looks like the python driver will do the right thing when you specify the DOTALL option to compiled regex objects.

Comment by Charles-Henri d'Adhémar [ 15/Apr/11 ]

Thanks a lot for having done so fast
Also I did not know about the $options trick for Javascript. Any idea whether I have to use the $options with the pymongo driver too ? With pymongo you specify a regular expression object for which the flags are already set into it. I guess using the $options in pymongo will work in any case and is safer to use, am I right ?

Comment by Mathias Stearn [ 14/Apr/11 ]

Thanks for the patch. If you want to use the 's' flag from javascript you will need to use the following syntax:

db.foo.find({fieldName: { $regex: 'asdf.*asdf', $options: 'is'}})

Comment by auto [ 14/Apr/11 ]

Author:

{u'login': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Add support for s (DOT_ALL) regex option SERVER-2943
Branch: master
https://github.com/mongodb/mongo/commit/07502672a2f8883081b20ec811fb86664d8ad3bb

Generated at Thu Feb 08 03:01:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.