Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

named capture groups with PCRE matching (Was: PATCH: migrate pcre module to pcre2)



2023-05-06 01:35:46 +0200, Oliver Kiddle:
[...]
> When looking at PCRE documentation for this, other ideas for extensions
> I saw would be to support:
> 
>  * named capture groups
>    (either to an associative array or to variables directly?)
[...]

I was thinking about that when answering
https://unix.stackexchange.com/questions/742664/bash-posix-regex-optional-groups/742680#742680
recently.

Maybe we could do:

typeset -A match
if [[ aa =~ '(?<foo>.)(?<bar>)' ]]
  print -r -- $match[foo] $match[bar]

That is if $match is an associative array, store the named
capture groups there. Same for pcre_match -a array (or add a -A
assoc there)

There's the question of $mbegin / $mend. Should all three
$match, $mbegin and $mend be automatically converted to assoc if
any of them is an assoc?

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author