Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Misc Library
    • Labels:
      None

      Description

      There's a Regex.quoteReplacement in the standard library, but no Regex.quote. Given that quoting regex metacharacters is a common operation, I think it's a bit ugly that one has to drop down to the Java API every time.

        Activity

        Hide
        Christoffer Sawicki added a comment -
        Show
        Christoffer Sawicki added a comment - Pull request: https://github.com/scala/scala/pull/3317
        Hide
        A. P. Marki added a comment - - edited

        I haven't submitted this PR yet, but what do you think of:

        https://github.com/som-snytt/scala/blob/a2e243369c18a5c1991dfff59644d710fa6395b5/src/library/scala/util/matching/Regex.scala#L467

        "a*b".r.quoted with the additional use case r"a*b".quoted for the regex interpolator.

        Open question how to compose quoted parts; I haven't looked at it, but it must be nicely done somewhere. E.g.,

        (a\*b)*
        is
        s"(${Pattern quote "a*b"})*".r
        , is there a nicer way.

        Show
        A. P. Marki added a comment - - edited I haven't submitted this PR yet, but what do you think of: https://github.com/som-snytt/scala/blob/a2e243369c18a5c1991dfff59644d710fa6395b5/src/library/scala/util/matching/Regex.scala#L467 "a*b".r.quoted with the additional use case r"a*b".quoted for the regex interpolator. Open question how to compose quoted parts; I haven't looked at it, but it must be nicely done somewhere. E.g., (a\*b)* is s"(${Pattern quote "a*b"})*".r , is there a nicer way.
        Hide
        Christoffer Sawicki added a comment -

        (I've replied to A.P Marki on GitHub where I first saw the message.)

        Show
        Christoffer Sawicki added a comment - (I've replied to A.P Marki on GitHub where I first saw the message.)
        Hide
        A. P. Marki added a comment -

        Complementary, not competing:

        https://github.com/scala/scala/pull/3343

        It allows for instance:

            val q = "[]".r.quoted
            val r = s"Array$q".r
        
        Show
        A. P. Marki added a comment - Complementary, not competing: https://github.com/scala/scala/pull/3343 It allows for instance: val q = "[]".r.quoted val r = s"Array$q".r
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/3317

          People

          • Assignee:
            Christoffer Sawicki
            Reporter:
            Christoffer Sawicki
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development