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)
- X-seq: zsh-workers 51724
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Oliver Kiddle <opk@xxxxxxx>
- Cc: Zsh workers <zsh-workers@xxxxxxx>
- Subject: named capture groups with PCRE matching (Was: PATCH: migrate pcre module to pcre2)
- Date: Sat, 6 May 2023 05:44:45 +0100
- Archived-at: <https://zsh.org/workers/51724>
- In-reply-to: <81584-1683329746.147485@6Tk5.mCsC.BbNC>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Oliver Kiddle <opk@xxxxxxx>, Zsh workers <zsh-workers@xxxxxxx>
- References: <81584-1683329746.147485@6Tk5.mCsC.BbNC>
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