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*) <> <>
In reply to Regex Minimal Quantifiers by pr33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |