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

Explain Ruby vs MongoDB/PCRE regular expressions better

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.11.0
    • Affects Version/s: None
    • Component/s: BSON, Docs
    • None
    • Fully Compatible

      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.

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

              Created:
              Updated:
              Resolved: