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 (rebased #665) #1039

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Nov 29, 2022

  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 authored and Duologic committed Nov 29, 2022
    Configuration menu
    Copy the full SHA
    4223ee1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e548dd9 View commit details
    Browse the repository at this point in the history