catfish1116 has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a program that would take a line of text, match on a word that would end in 'a' and also capture up to the next 5 characters. Here is the program.
r/bin/perl use v5.12; use warnings; ## 9/26/19 ## Program uses named captures instead of $1 chomp(my $text = <STDIN>); while (<>) { # take one input line at a time chomp; if ( $text =~ m/((?<word1>\b\w*a\b))(?<word2>\s+++++))/) { print "Matched: |$`<$&>$'|\n"; # the special match vars print " 'word' contains '$+{word1} $+<word2>'\n"; } else { print "No match: |$_|\n"; }
and here is the errors that I'm getting
Nested quantifiers in regex; marked by <-- HERE in m/((?<word1>\b\w*a\ +b))(?<word2>\s+++ <-- HERE ++))/ at ./Chapter8_Exer5 line 12
TIA The catfish
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Trying out 2 captures
by Fletch (Bishop) on Sep 26, 2019 at 21:08 UTC | |
Re: Trying out 2 captures
by AnomalousMonk (Archbishop) on Sep 26, 2019 at 21:40 UTC |