int array_len;
int array_idx;
int prev_match_end;
+ int prev_valid_match_end;
int start_search;
int maxlen = 0; /* largest fetch length in characters */
/* search for the pattern, perhaps repeatedly */
prev_match_end = 0;
+ prev_valid_match_end = 0;
start_search = 0;
while (RE_wchar_execute(cpattern, wide_str, wide_len, start_search,
pmatch_len, pmatch))
matchctx->nmatches++;
/*
- * check length of unmatched portion between end of previous match
- * and start of current one
+ * check length of unmatched portion between end of previous valid
+ * (nondegenerate, or degenerate but not ignored) match and start
+ * of current one
*/
if (fetching_unmatched &&
pmatch[0].rm_so >= 0 &&
- (pmatch[0].rm_so - prev_match_end) > maxlen)
- maxlen = (pmatch[0].rm_so - prev_match_end);
+ (pmatch[0].rm_so - prev_valid_match_end) > maxlen)
+ maxlen = (pmatch[0].rm_so - prev_valid_match_end);
+ prev_valid_match_end = pmatch[0].rm_eo;
}
prev_match_end = pmatch[0].rm_eo;
* input string
*/
if (fetching_unmatched &&
- (wide_len - prev_match_end) > maxlen)
- maxlen = (wide_len - prev_match_end);
+ (wide_len - prev_valid_match_end) > maxlen)
+ maxlen = (wide_len - prev_valid_match_end);
/*
* Keep a note of the end position of the string for the benefit of
{"","","","","","",""}
(1 row)
+SELECT regexp_split_to_array('123456','');
+ regexp_split_to_array
+-----------------------
+ {1,2,3,4,5,6}
+(1 row)
+
+SELECT regexp_split_to_array('123456','(?:)');
+ regexp_split_to_array
+-----------------------
+ {1,2,3,4,5,6}
+(1 row)
+
+SELECT regexp_split_to_array('1','');
+ regexp_split_to_array
+-----------------------
+ {1}
+(1 row)
+
-- errors
SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo;
ERROR: invalid regexp option: "z"
SELECT regexp_split_to_array('123456','1');
SELECT regexp_split_to_array('123456','6');
SELECT regexp_split_to_array('123456','.');
+SELECT regexp_split_to_array('123456','');
+SELECT regexp_split_to_array('123456','(?:)');
+SELECT regexp_split_to_array('1','');
-- errors
SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo;
SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');