![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Finding match offsets of named captures in 5.10 regexby nobull (Friar) |
on Sep 27, 2008 at 17:21 UTC ( #714041=perlquestion: print w/replies, xml ) | Need Help?? |
nobull has asked for the wisdom of the Perl Monks concerning the following question:
The special variables @- and @+ can give me the start and end offsets of regex captures by number. In 5.10 we can now have named captures but %- and %+ contain the actual strings matched not the offsets.
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.
Is there a way of doing this that still works for regex with a mixture of named and unnamed captures?
Back to
Seekers of Perl Wisdom
|
|