pr33 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Can any one please explain me the below code ? Isn't the minimal quantifier(.*?) in this case be supposed to match 'I have ' for the first capture and then from number 2 till end of the string for second capture $2 . The O/p returns nothing for $1 and $2 .
Here is my code
#!/usr/bin/perl use warnings; use strict; ############### my $str = "I have 2 numbers: 53147"; my @pats = qw { (.*?)(\d*) }; foreach my $pat (@pats) { printf "%-12s ", $pat; if ( $str =~ /$pat/ ) { print "<$1> <$2>\n"; } else { print "FAIL\n"; } }
$ ./regex.pl
(.*?)(\d*) <> <>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Minimal Quantifiers
by huck (Prior) on May 24, 2017 at 04:54 UTC | |
by pr33 (Scribe) on May 24, 2017 at 05:14 UTC | |
|
Re: Regex Minimal Quantifiers
by haukex (Archbishop) on May 24, 2017 at 06:00 UTC | |
by pr33 (Scribe) on May 24, 2017 at 15:23 UTC | |
by haukex (Archbishop) on May 24, 2017 at 15:56 UTC | |
by pr33 (Scribe) on May 24, 2017 at 17:37 UTC | |
|
Re: Regex Minimal Quantifiers
by hippo (Archbishop) on May 24, 2017 at 08:05 UTC |