Polyglot has asked for the wisdom of the Perl Monks concerning the following question:
my $text = 'This is just an arbitrary example of text.'; #ONLY TWO WORDS ARE CAPTURED--WE WANT TO HIGHLIGHT ONLY THOSE my $query = qr~(?:(?:This)|(?:That)).*?(just).*?(arbitrary).*?$~; #THIS WOULD HIGHLIGHT THE ENTIRE LINE $text =~ s~($query)~<span class="highlight">$1</span>~g;
Blessings,
~Polyglot~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Highlighting only captured groups from larger regex
by Corion (Patriarch) on Dec 12, 2022 at 21:55 UTC | |
|
Re: Highlighting only captured groups from larger regex
by tybalt89 (Monsignor) on Dec 12, 2022 at 22:25 UTC | |
by Polyglot (Chaplain) on Dec 13, 2022 at 02:17 UTC | |
by LanX (Saint) on Dec 13, 2022 at 12:29 UTC | |
|
Re: Highlighting only captured groups from larger regex
by hippo (Archbishop) on Dec 12, 2022 at 21:46 UTC | |
|
Re: Highlighting only captured groups from larger regex
by rsFalse (Chaplain) on Dec 13, 2022 at 11:53 UTC |