You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which i understand it makes sense because the regex function only asserts whether the text provided matches the regex or not. However, what i need here is to extract the api_key and map it to a new value. Is this doable?
That is a good idea! Right now the regex function only tests whether a string matches or not: it returns true or false. It will be very useful to be able to extract one (or multiple) matches from a string using a regex.
It is probably best to create a new function that allows doing that. We will have to think through what this function should return and what options it should have. A regex can have one or multiple match groups for example. Also, you can either want the first match or all matches.
Alternatively we could change the existing function regex to return match results. That would make it slower when used to just filter. It would be nice if we could still optimize for that case.
How about new functions regexExtract and regexExtractAll that returns match results as a match object/array of match objects?
Could model match objects based on how javascript does things (but make it an actual object instead of an array with extra properties tacked on).
Might look something like this, where the match object has a .results property that contains an array with the first element being the full match followed by any matched groups. There would also be a .groups property that contains an object mapping named capture groups to their captures. (Javascript includes .index, .length, and .input properties as well that should probably be included but I'm leaving them out on these examples for the sake of brevity)
I've worked out a PR and ported this to the Python library too. I'm still thinking about the most suitable return type for the new functions. JavaScript returns an array where the first item is the actual match, optionally followed by capturing groups. In our case we want to return named capturing groups too, so that is three separate things. Inspired by the regex functions of Python and Kotlin, it may be good to explicitely return those. Right now I have the following syntax:
// function matchjsonquery('Save the date: 2025-12-25!','match(get(), "(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<date>[0-9]{2})")')// {// "value": "2025-12-25", // "groups": ["2025", "12", "25"],// "namedGroups": {"year": "2025", "month": "12", "date": "25"}// }// function matchAlljsonquery('We will be on holiday from 2026-08-14 till 2026-08-28','matchAll(get(), "(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<date>[0-9]{2})")')// [// {// "value": "2026-08-14",// "groups": ["2026", "08", "14"],// "namedGroups": {"year": "2026", "month": "08", "date": "14"}// },// {// "value": "2026-08-28",// "groups": ["2026", "08", "28"],// "namedGroups": {"year": "2026", "month": "08", "date": "28"}// }// ]
Instead of { value, groups, namedGroups } we could also name the properties { value, groups, groupValues } where groups then contains the named capturing groups and groupValues the array with the unnamed capturing groups.
Activity
josdejong commentedon Oct 22, 2025
That is a good idea! Right now the
regexfunction only tests whether a string matches or not: it returns true or false. It will be very useful to be able to extract one (or multiple) matches from a string using a regex.It is probably best to create a new function that allows doing that. We will have to think through what this function should return and what options it should have. A regex can have one or multiple match groups for example. Also, you can either want the first match or all matches.
Alternatively we could change the existing function
regexto return match results. That would make it slower when used to justfilter. It would be nice if we could still optimize for that case.Any thoughts on this?
iamevn commentedon Nov 2, 2025
How about new functions
regexExtractandregexExtractAllthat returns match results as a match object/array of match objects?Could model match objects based on how javascript does things (but make it an actual object instead of an array with extra properties tacked on).
Might look something like this, where the match object has a
.resultsproperty that contains an array with the first element being the full match followed by any matched groups. There would also be a.groupsproperty that contains an object mapping named capture groups to their captures. (Javascript includes.index,.length, and.inputproperties as well that should probably be included but I'm leaving them out on these examples for the sake of brevity)(a js implementation of this would be a pretty thin wrapper around
String.prototype.match()/String.prototype.matchAll())josdejong commentedon Nov 5, 2025
Thanks for working out this proposal Evan, I like it!
The names
regexExtractandregexExtractAllmake sense, though they are quite long. How aboutmatchandmatchAll?I've made a start implementing this idea in #26. Feedback is welcome.
josdejong commentedon Dec 2, 2025
I've worked out a PR and ported this to the Python library too. I'm still thinking about the most suitable return type for the new functions. JavaScript returns an array where the first item is the actual match, optionally followed by capturing groups. In our case we want to return named capturing groups too, so that is three separate things. Inspired by the regex functions of Python and Kotlin, it may be good to explicitely return those. Right now I have the following syntax:
See docs of the new functions:
Pull requests:
Instead of
{ value, groups, namedGroups }we could also name the properties{ value, groups, groupValues }wheregroupsthen contains the named capturing groups andgroupValuesthe array with the unnamed capturing groups.Any thoughts on this?
josdejong commentedon Dec 5, 2025
@iamevn and @takato1314 do you have any feedback/thoughts?
iamevn commentedon Dec 6, 2025
I really like splitting out the matched value from the capture groups like this and
{ value, groups, namedGroups }seems intuitive to me 👍Good callout on the docs for
(?<name...)vs(?P<name>...).josdejong commentedon Dec 6, 2025
Thanks for the feedback Evan!
feat: #25 implement functions `match` and `matchAll` (#2)
josdejong commentedon Dec 9, 2025
Implemented now via #26, published in
v5.1.0sarashed731-prog commentedon Jul 30, 2026
bull request