I am learning Perl regex, and I am trying to extract digits from a string, e.g.
my $text = "abc000142gh";
i.e. I would like to extract 000142 as a string in a scalar variable.
I have tried:
my $digits = $text ~= /(+d)/;
my $digits = $text ~= m/(+d)/;
my $digits = $text ~= m/(+d)/g;
my $digits = $text ~= /(+d)/g;
but none of them seem to work. Is there a way to do this with a one-liner?
This works:
The differences:
=~, not~=.\dmeans a digit,dstands for itself.+(repetition) is used after the symbol to repeat, not before.