Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Regex.quote #8107

Closed
scabug opened this issue Dec 29, 2013 · 6 comments
Closed

Add Regex.quote #8107

scabug opened this issue Dec 29, 2013 · 6 comments
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Dec 29, 2013

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.

@scabug
Copy link
Author

@scabug scabug commented Dec 29, 2013

@scabug
Copy link
Author

@scabug scabug commented Dec 29, 2013

@qerub said:
Pull request: scala/scala#3317

@scabug
Copy link
Author

@scabug scabug commented Dec 29, 2013

@som-snytt said (edited on Dec 29, 2013 8:47:47 PM UTC):
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., {code}(a*b){code} is {code}s"(${Pattern quote "ab"})*".r{code}, is there a nicer way.

@scabug
Copy link
Author

@scabug scabug commented Jan 4, 2014

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

@scabug
Copy link
Author

@scabug scabug commented Jan 8, 2014

@som-snytt said:
Complementary, not competing:

scala/scala#3343

It allows for instance:

    val q = "[]".r.quoted
    val r = s"Array$q".r

@scabug
Copy link
Author

@scabug scabug commented Jan 15, 2014

@scabug scabug closed this Jan 15, 2014
@scabug scabug added this to the 2.11.0-M8 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant