-
Notifications
You must be signed in to change notification settings - Fork 438
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 support using RE2 #665
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Hey @googlebot, I signed it. 😄 |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Linux and OSX build fails on Bazel and CMake builds should be unaffected since they pull in the RE2 source via Git. |
Introduces 5 new built-in methods to the stdlib: - `regexFullMatch(pattern, str)` -- Full match regex - `regexPartialMatch(pattern, str)` -- Partial match regex - `regexQuoteMeta(str)` -- Escape regex metachararacters - `regexReplace(str, pattern, to)` -- Replace single occurance using regex - `regexGlobalReplace(str, pattern, to)` -- Replace globally using regex Since both `regexFullMatch` and `regexPartialMatch` can perform captures these functions return a "match" object upon match or `null` otherwise. For example: ``` $ ./jsonnet -e 'std.regexFullMatch("h(?P<mid>.*)o", "hello")' { "captures": [ "ell" ], "namedCaptures": { "mid": "ell" }, "string": "hello" } ``` Introduces a dependency on RE2 2019-06-01. Builds tested using make, CMake and Bazel on Ubuntu 18.04.
It looks like on OSX you can do:
Judging by https://docs.travis-ci.com/user/installing-dependencies/#installing-packages-on-macos and http://macappstore.org/re2/ |
I could really use this, is it still planned to include this? |
Will there be any progress on landing regex support for jsonnet? Almost been an year. Just wondering what the status of this PR is. |
We're happy to go forward if the PR author (or someone else) is willing to pick this up again and fix the build issues. |
Thanks for quick response @sbarzowski. I see there are some merge conflicts and travis is failing with |
I assume that anyone picking this up would have to find a compatible solution on the Go side too? (I.e. the same regex syntax and semantics) |
Golang stdlib is "almost" re2. My stance on this is that regexps are too useful to miss out on them completely, but fully portable, formally-defined solutions are not available, so I'd be willing to compromise and have best-effort compatibility. |
That may be necessary if there is no alternative. We would need to allow the jsonnet code to know what implementation it's running as so it can choose a regex for that implementation. I also wonder what the impact would be for the unofficial implementations in rust, scala, etc. |
I think, in practice what people almost always want are very simple regexps which look the same everywhere, so probably checking platform is not going to be necessary for what the people actually want... |
I rebased this PR here: #1039 |
Introduces 5 new built-in methods to the stdlib:
regexFullMatch(pattern, str)
-- Full match regexregexPartialMatch(pattern, str)
-- Partial match regexregexQuoteMeta(str)
-- Escape regex metachararactersregexReplace(str, pattern, to)
-- Replace single occurance using regexregexGlobalReplace(str, pattern, to)
-- Replace globally using regexSince both
regexFullMatch
andregexPartialMatch
can perform capturesthese functions return a "match" object upon match or
null
otherwise.For example:
Introduces a dependency on RE2 2019-06-01.
Builds tested using make, CMake and Bazel on Ubuntu 18.04.
Fixes #107.