Perl one-liner to extract groups of characters
perl
Solution
perl -pe's/\D*(\d+).*/$1/'
or
perl -nE'/\d+/&&say$&'
or
perl -nE'say/(\d+)/'
or
perl -ple's/\D//g'
or may be
perl -nE'$,=" ";say/\d+/g'
Problem
I am trying to extract a group of characters with a Perl one-liner, but I have been unsuccessful: ``` echo "hello_95_.txt" | perl -ne 's/.*([0-9]+).*/\1/' ``` Returns nothing, while I would like it to return `95`. How can I do this with Perl? Update: Note that, in contrast to the suggested duplicate, I am interested in how to do this from the command-line. Surely this looks like a subtle difference, but it's not straightforward unless you already know how to effectively use Perl one-liners. Since people are asking, eventually I want to learn to use Perl to write powerful one-liners, but most immediately I need a one-liner to extract consecutive digits from each line in a large text file.