+ at least one, {,1} * zero or more, {0,} /\d{7,11}/ 7 to 11 digits /(bam){2}/ matches "bambam"
Quantifiers are greedy. Minimal matching is selected by a “?” following a quantifier, e.g.:
my $t = "abc123"; $t =~ /(.+)\d/; # greedy print "$1\n";
produces abc12, while
my $t = "abc123"; $t =~ /(.+?)\d/; # ungreedy print "$1\n";
prints abc.
Regular expressions match as early as possible, e.g. if
s/x*//;
is applied to the string $_ = "fred xxxx john";
nothing is substituted because x*
includes the empty string which
stands at the beginning of every string.