-
^ is match at beginning ..
-
\d is looking for a digit character
-
+ is find
\d 1 or more times
-
(...) Groups subexpressions for capturing to $1, $2,$3 ...
In this case, $scrip will return the the complete sub expression match (which is inside the brackets : (\d+\.\d+\.\d+\.\d+) ):
my ($scrip) = $ARGV[0] =~ /^(\d+\.\d+\.\d+\.\d+)/;
print "\$scrip returned : $scrip\n";
print "match 1 : $1\nmatch 2 : $2\nmatch 3 : $3\nmatch 4 : $4\n";
INPUT
C:\Perl\bin>perl bleh.pl 1.0.3.3_1.3.45.44
OUTPUT
$scrip returned : 1.0.3.3
match 1 : 1.0.3.3
match 2 :
match 3 :
match 4 :
If "
\d+\.\d+\.\d+\.\d+" wasn't inside the brackets, $scrip would return 1, if it matched the reg-ex:
my ($scrip) = $ARGV[0] =~ /\d+\.\d+\.\d+\.\d+/;
if($scrip) {
print "matched $ARGV[0] !\n";
}else{
print "did not match $ARGV[0] !\n";
}
print "\$scrip = $scrip\n";
OUTPUT EXAMPLES:
C:\Perl\bin>perl bleh.pl 13.3.3.3_
matched 13.3.3.3_ !
$scrip = 1
C:\Perl\bin>perl bleh.pl 13.3.
did not match 13.3. !
$scrip =