Suppose I have a string like this:
my $str = "blah, 10 4.2 blah.. a2 ...blah 34xx2 blah.... blah";
I need to extract numbers and any strings that have one or more digit(s) out of $str, i.e. in the example above, I need to extract the following substrings:
10 4.2 a2 34xx2
I know one way to do this --
But I don't like it. There should be a better way to implement this. Could someone help? Many thanks!!
my $str = "blah, 10 4.2 blah.. a2 ...blah 34xx2 blah.... blah";
I need to extract numbers and any strings that have one or more digit(s) out of $str, i.e. in the example above, I need to extract the following substrings:
10 4.2 a2 34xx2
I know one way to do this --
Code:
my @buf = split(/\s+/, $str);
my @keep;
foreach (@buf) {
if($_ =~ /\d/) {
push @keep, $_;
}
}
But I don't like it. There should be a better way to implement this. Could someone help? Many thanks!!