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

triple-quoted regular expressions, triple-quoted string docs #4927

Closed
gitfoxi opened this issue Nov 26, 2013 · 5 comments
Closed

triple-quoted regular expressions, triple-quoted string docs #4927

gitfoxi opened this issue Nov 26, 2013 · 5 comments
Labels
docs This change adds or pertains to documentation help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@gitfoxi
Copy link
Contributor

gitfoxi commented Nov 26, 2013

I notice that triple-quoted strings have been implemented. This is a good feature.

  1. It is not documented in the manual under Strings.
  2. It is not implemented for Regex strings

I wish I could do this:

match(r"""\s*
  "[^"]*"\s*
  """ix, """
  "foo"
  """)

[Edit: title, formatting – @StefanKarpinski]

@StefanKarpinski
Copy link
Sponsor Member

Good issue. Thanks for filing it.

@StefanKarpinski
Copy link
Sponsor Member

So, I changed the title to make it more general and then realized that we already support triple-quoted non-standard strings, but you just have to implement the corresponding @r_mstr macro for them. So yeah, the original title was accurate. This is pretty easy to do. Someone just needs to implement the @r_mstr macro.

@gitfoxi
Copy link
Contributor Author

gitfoxi commented Nov 26, 2013

This works:

macro r_mstr(p,o) Regex(p,o) end

Then I can do

julia> re = r"""
       "[^"]*"
       """xs
r"
       \"[^\"]*\"
       "sx

julia> match(re, """
       "asdf"
       """)
RegexMatch("\"asdf\"")

The macro just needs to go in share/julia/base/regex.jl and then some documentation in share/julia/doc/manual/strings.rst

@gitfoxi
Copy link
Contributor Author

gitfoxi commented Nov 26, 2013

Maybe I will do the PR since it's so easy. Making the actual PR is the hard part ...

@gitfoxi
Copy link
Contributor Author

gitfoxi commented Nov 26, 2013

macro r_mstr(pattern, flags...) Regex(pattern, flags...) end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants