in reply to Regex to extract digits
But that would scare many of us because it doesn't check whether there might be more or less than two digits, or whether there are strange characters following the digits, and other such errors. So for the string you showed us, we'd probably feel like saying something likemy $thing = '1232-32'; my $value; if( $thing =~ m/-(\d\d)/ ) { $value = $1; printf "I found '%s'\n", $value; } else { printf "I didn't find what I was expecting in '%s'\n", $thing; }
but that might be too much checking for your purposes.if( $thing =~ m/^\d+-(\d+)$/ ) {
|
|---|