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

Support the PCRE Regex PARTIAL_{HARD,SOFT} opts. #33646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Oct 23, 2019

Make exec aware of the PARTIAL_HARD and PARTIAL_SOFT flags set on a Regex object.

This allows match() to return partial matches if they are requested by the user in the Regex options. Currently we are ignoring these options, since partial matches are returned as a -2 status code, and we are not currently checking for that.


Partial Regex matches are often used for interactive validation of UI fields (e.g. in a web page):

  • You could have a regex describing the format of the field you expect, which you check for a (partial) match as the user types, so you can catch as soon as they have entered something that is invalid (because no completion of it will satisfy the regex), and underline the text in red (or something).
  • For example, something like this:
    if (partial_match(r"\d\d/\d\d/\d\d\d\d", input) == nothing) throw("input must be a \"dd/mm/yyyy\" string") end

I didn't include a convenience function for constructing a partial regex, which maybe we should also include in this PR?
Right now we're constructing them in our code like this:

partial(str::AbstractString) = Regex(str, Base.DEFAULT_COMPILER_OPTS,
    Base.DEFAULT_MATCH_OPTS | Base.PCRE.PARTIAL_HARD)

But it might make sense to add a flag to the r"" macro, in the same style as the m/i flags? I couldn't find any equivalent such flags online -- where is the inspiration for those one-letter flags taken from?

Or this could be done in follow-up PRs.

Make `exec` aware of the `PARTIAL_HARD` and `PARTIAL_SOFT` flags set on
a `Regex` object.
@rfourquet
Copy link
Member

Ouch I'm sorry, I just opened a competing PR, I didn't think of checking earlier on github before starting mine! Quite funny that we thought about doing the same thing within a 3-days interval :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants