in reply to Re: Regex to extract number from text file
in thread Regex to extract number from text file
except that you don't want the /g (global) switch on the regex! Consider:
use strict; use warnings; my $str = 'wibble 10'; print "Matched $1\n" if $str =~ /(\d+)/g; print "Matched $1\n" if $str =~ /(\w+)/g;
Prints:
Matched 10
Because of the /g switch the second match fails because is starts searching from where the first match left off.
|
|---|