nobull has asked for the wisdom of the Perl Monks concerning the following question:
Is there any way to get the offsets from the capture names? Alternatively is there a way to convert the capture names into numbers that can be used to subscript the arrays?
The following code maps names to numbers if the regex contains only named captures but falls apart if there are named ones too.
sub named_capture_map { my %n; @n{re::regnames(1)} = (1 .. $#+); \%n; }
Is there a way of doing this that still works for regex with a mixture of named and unnamed captures?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding match offsets of named captures in 5.10 regex
by JavaFan (Canon) on Sep 27, 2008 at 21:11 UTC | |
by JadeNB (Chaplain) on Sep 28, 2008 at 18:40 UTC | |
|
Re: Finding match offsets of named captures in 5.10 regex
by Anonymous Monk on Mar 03, 2010 at 18:21 UTC | |
|
Re: Finding match offsets of named captures in 5.10 regex
by LanX (Saint) on Jan 30, 2013 at 09:30 UTC |