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 support using RE2 #665

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

Add RegEx support using RE2 #665

wants to merge 1 commit into from

Commits on Jun 2, 2019

  1. Add RegEx support using RE2

    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.
    dcoles committed Jun 2, 2019
    Configuration menu
    Copy the full SHA
    71ee2f1 View commit details
    Browse the repository at this point in the history