Allow to extract empty matches in "extractAll" function #1493.

This commit is contained in:
Alexey Milovidov 2017-11-18 05:48:11 +03:00
parent 729b114c15
commit 14e069f748
3 changed files with 7 additions and 2 deletions

View File

@ -305,13 +305,13 @@ public:
if (!pos || pos > end)
return false;
if (!re->match(pos, end - pos, matches) || !matches[capture].length)
if (!re->match(pos, end - pos, matches) || !matches[0].length)
return false;
token_begin = pos + matches[capture].offset;
token_end = token_begin + matches[capture].length;
pos += matches[capture].offset + matches[capture].length;
pos += matches[0].offset + matches[0].length;
return true;
}

View File

@ -0,0 +1 @@
{"a":"1","b":"2","c":"","d":"4"} ['a','b','c','d'] ['1','2','','4']

View File

@ -0,0 +1,4 @@
SELECT
'{"a":"1","b":"2","c":"","d":"4"}' AS json,
extractAll(json, '"([^"]*)":') AS keys,
extractAll(json, ':"([^"]*)"') AS values;