mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-12-29 16:25:35 +01:00
52405, 52502: add empty elements to $match for optional captures that don't match
This commit is contained in:
parent
742049a4cb
commit
698af7bc13
3 changed files with 12 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
||||||
2024-01-26 Oliver Kiddle <opk@zsh.org>
|
2024-01-26 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* 52405, 52502: Src/Modules/pcre.c, Test/V07pcre.ztst:
|
||||||
|
add empty elements to $match for optional captures that don't match
|
||||||
|
|
||||||
* github #110: opensauce04: Completion/Redhat/Command/_dnf:
|
* github #110: opensauce04: Completion/Redhat/Command/_dnf:
|
||||||
Fix incorrect completion for `dnf --showduplicates`
|
Fix incorrect completion for `dnf --showduplicates`
|
||||||
|
|
||||||
|
|
|
@ -391,6 +391,8 @@ bin_pcre_match(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
pcre_mdata = pcre2_match_data_create_from_pattern(pcre_pattern, NULL);
|
pcre_mdata = pcre2_match_data_create_from_pattern(pcre_pattern, NULL);
|
||||||
ret = pcre2_match(pcre_pattern, (PCRE2_SPTR) plaintext, subject_len,
|
ret = pcre2_match(pcre_pattern, (PCRE2_SPTR) plaintext, subject_len,
|
||||||
offset_start, 0, pcre_mdata, mcontext);
|
offset_start, 0, pcre_mdata, mcontext);
|
||||||
|
if (ret > 0)
|
||||||
|
ret = pcre2_get_ovector_count(pcre_mdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret==0) return_value = 0;
|
if (ret==0) return_value = 0;
|
||||||
|
@ -479,7 +481,8 @@ cond_pcre_match(char **a, int id)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (r>0) {
|
else if (r>0) {
|
||||||
zpcre_get_substrings(pcre_pat, lhstr_plain, pcre_mdata, r, svar, avar,
|
uint32_t ovec_count = pcre2_get_ovector_count(pcre_mdata);
|
||||||
|
zpcre_get_substrings(pcre_pat, lhstr_plain, pcre_mdata, ovec_count, svar, avar,
|
||||||
".pcre.match", 0, isset(BASHREMATCH), !isset(BASHREMATCH));
|
".pcre.match", 0, isset(BASHREMATCH), !isset(BASHREMATCH));
|
||||||
return_value = 1;
|
return_value = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -108,6 +108,11 @@
|
||||||
>0 xo→t →t
|
>0 xo→t →t
|
||||||
>0 Xo→t →t
|
>0 Xo→t →t
|
||||||
|
|
||||||
|
[[ foo =~ (pre)?f(o*)(opt(i)onal)?(y)* ]]
|
||||||
|
typeset -p match
|
||||||
|
0:Empty string for optional captures that don't match
|
||||||
|
>typeset -g -a match=( '' oo '' '' '' )
|
||||||
|
|
||||||
string="The following zip codes: 78884 90210 99513"
|
string="The following zip codes: 78884 90210 99513"
|
||||||
pcre_compile -m "\d{5}"
|
pcre_compile -m "\d{5}"
|
||||||
pcre_match -b -- $string && print "$MATCH; ZPCRE_OP: $ZPCRE_OP"
|
pcre_match -b -- $string && print "$MATCH; ZPCRE_OP: $ZPCRE_OP"
|
||||||
|
|
Loading…
Reference in a new issue