New strmatch/strmatchx DSL functions (#1448)

* New `match`/`matchx` DSL functions

* unit-test cases

* match/matchx -> strmatch/strmatchx

* help strings for strmatch and strmatchx

* update regex doc page re strmatch/strmatchx

* unit-test update
This commit is contained in:
John Kerl 2023-12-19 14:34:54 -05:00 committed by GitHub
parent 211b15ad4f
commit c6b745537a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 747 additions and 34 deletions

View file

@ -0,0 +1 @@
mlr --ojsonl --from ${CASEDIR}/input put -f ${CASEDIR}/mlr

View file

View file

@ -0,0 +1,11 @@
{"x": "a", "y": "b", "z": false}
{"x": "abc", "y": "ab", "z": true}
{"x": " 345 78 ", "y": "([0-9]+)", "z": true}
{"x": " 345 78 ", "y": "([0-9]+) ([0-9]+)", "z": true}
{"x": " 345 78 ", "y": "([0-9]+)(.)([0-9]+)", "z": true}
{"x": "", "y": "", "z": true}
{"x": "", "y": "b", "z": false}
{"x": "a", "y": "", "z": true}
{"x": "a", "z": (error)}
{"y": "b", "z": (error)}
{"foo": "bar", "z": (error)}

View file

@ -0,0 +1,11 @@
x=a,y=b
x=abc,y=ab
x= 345 78 ,y=([0-9]+)
x= 345 78 ,y=([0-9]+) ([0-9]+)
x= 345 78 ,y=([0-9]+)(.)([0-9]+)
x=,y=
x=,y=b
x=a,y=
x=a
y=b
foo=bar

View file

@ -0,0 +1 @@
$z = strmatch($x, $y)

View file

@ -0,0 +1 @@
mlr --ojson --from ${CASEDIR}/input put -f ${CASEDIR}/mlr

View file

View file

@ -0,0 +1,110 @@
[
{
"x": "a",
"y": "b",
"z": {
"matched": false
}
},
{
"x": "abc",
"y": "ab",
"z": {
"matched": true,
"full_capture": "ab",
"full_start": 1,
"full_end": 2
}
},
{
"x": " 345 78 ",
"y": "([0-9]+)",
"z": {
"matched": true,
"full_capture": "345",
"full_start": 3,
"full_end": 5,
"captures": ["345"],
"starts": [3],
"ends": [5]
}
},
{
"x": " 345 78 ",
"y": "([0-9]+) ([0-9]+)",
"z": {
"matched": true,
"full_capture": "345 78",
"full_start": 3,
"full_end": 8,
"captures": ["345", "78"],
"starts": [3, 7],
"ends": [5, 8]
}
},
{
"x": " 345 78 ",
"y": "([0-9]+)(.)([0-9]+)",
"z": {
"matched": true,
"full_capture": "345 78",
"full_start": 3,
"full_end": 8,
"captures": ["345", " ", "78"],
"starts": [3, 6, 7],
"ends": [5, 6, 8]
}
},
{
"x": "",
"y": "",
"z": {
"matched": true,
"full_capture": "",
"full_start": 1,
"full_end": 0
}
},
{
"x": "",
"y": "b",
"z": {
"matched": false
}
},
{
"x": "a",
"y": "",
"z": {
"matched": true,
"full_capture": "",
"full_start": 1,
"full_end": 0
}
},
{
"x": "a",
"z": (error)
},
{
"y": "b",
"z": (error)
},
{
"foo": "bar",
"z": (error)
},
{
"x": "1234567890abcdefghij",
"y": "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)",
"z": {
"matched": true,
"full_capture": "1234567890abcdefghij",
"full_start": 1,
"full_end": 20,
"captures": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
"starts": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
"ends": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
}
}
]

View file

@ -0,0 +1,12 @@
x=a,y=b
x=abc,y=ab
x= 345 78 ,y=([0-9]+)
x= 345 78 ,y=([0-9]+) ([0-9]+)
x= 345 78 ,y=([0-9]+)(.)([0-9]+)
x=,y=
x=,y=b
x=a,y=
x=a
y=b
foo=bar
x=1234567890abcdefghij,y=(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)

View file

@ -0,0 +1 @@
$z = strmatchx($x, $y)