my $s = "123 45 6 789";
while ($s =~ m/\d+/g) {
print "> $&\n";
}
####
> 123
> 45
> 6
> 789
##
##
my $s = "123 carrots 45 6 bananas 789";
while (1) {
$s =~ /\G(\d+)/gc and print "NUMBER $1\n" and next;
$s =~ /\G\s+/gc and print "SPACE\n" and next;
$s =~ /\G([a-z]+)/gc and print "WORD $1\n" and next;
$s =~ /\G$/gc and last;
}
##
##
NUMBER 123
SPACE
WORD carrots
SPACE
NUMBER 45
SPACE
NUMBER 6
SPACE
WORD bananas
SPACE
NUMBER 789
##
##
NUMBER 123
NUMBER 45
NUMBER 6
NUMBER 789
##
##
my $s = "123 carrots 45 6 bananas 789";
while ($s =~ /(\d+)/g) {
print "'$1' at position ", pos($s)-length($1), "\n";
}
##
##
'123' at position 0
'45' at position 15
'6' at position 18
'789' at position 29
##
##
my $s = "123 carrots 45 6 bananas 789";
while ($s =~ /(\d+)/g) {
print "'$1' at position ", pos($s)-length($1), "\n";
pos($s) += 13;
}
##
##
'123' at position 0
'5' at position 16
'89' at position 30