Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2236

Explain Ruby vs MongoDB/PCRE regular expressions better

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • bson-4.11.0
    • BSON, Docs
    • None
    • Fully Compatible

    Description

      In https://docs.mongodb.com/ruby-driver/master/tutorials/bson-v4/#regular-expressions we say that:

      > Ruby regular expressions always have BSON regular expressions' equivalent of 'm' flag on.

      While this is true, having /m on changes the meaning of . to include newlines.

      The principal difference between Ruby and PCRE regular expressions is the meaning of ^ and $ anchors, which in Ruby is not configurable and they always refer to beginning/end of line while in PCRE depending on whether regexp is multiline they refer to beginning/end of line or input.

      This ticket covers changing our documentation to:

      • Clearly describe this difference between Ruby and PCRE/MongoDB regexps.
      • Emphasize that compatibility can be attained by using \A and \z in regexps instead of ^ and $. mongo shell supports \A and \z anchors. But, see the next point for /m.
      • Come up with a way to deal with the fact that currently bson-ruby does add /m by default. Hopefully a way that does not involve code changes.

      In a later version of bson-ruby, we could consider dropping /m by default and instead requiring that users use \A and \z in their regular expressions to match the expected behavior of ^ and $ in PCRE/MQL.

      Attachments

        Activity

          People

            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: