Pathologically Eclectic Rubbish Lister | |
PerlMonks |
How to color the regex captured groups?by ovedpo15 (Pilgrim) |
on Aug 12, 2022 at 16:32 UTC ( [id://11146126]=perlquestion: print w/replies, xml ) | Need Help?? |
ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks! I have a array of hashes. Each hash contains a rexes rule. Given a path, I'm trying to iterate over the rules and find the first matching rule. I'm trying to add a small feature which will help users to debug (since the rexes are user custom) - I want to mark the groups in the given path. For example: In this case I got: /a/b/[RED]c[/RED]/[RED]d[/RED]. The current code: The @captures contains the group values that were captured (c and d in the example). I came a cross with the Term::ANSIColor module which can help me color the string without writing the color codes myself. So, what would be the best way to create a variable $output that is basically $path but colored given the captured groups? You can assume that there are always at least two groups.
Back to
Seekers of Perl Wisdom
|
|