jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Add RegEx support using RE2 (rebased #665)

Open Duologic opened this issue 2 years ago • 4 comments

Rebased #665:

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.

I ran make and make test on Linux, not sure how to trigger TravisCI.

Duologic avatar Nov 29 '22 19:11 Duologic

Anything else I should address? @sparkprime @sbarzowski

Duologic avatar Dec 07 '22 15:12 Duologic

Sorry it took so long to reply. Looks mostly good. Left some minor comments.

sbarzowski avatar Jan 17 '23 00:01 sbarzowski

After I've done the current release (hopefully today) let's move forward on regex support in both impls for the next release.

sparkprime avatar Apr 13 '23 13:04 sparkprime

After I've done the current release (hopefully today) let's move forward on regex support in both impls for the next release.

Sounds good!

sbarzowski avatar Jun 13 '23 22:06 sbarzowski