Given a filename in the form someletters_12345_moreleters.ext, I want to extract the 5 digits and put them into a variable.
So to emphasize the point, I
Ok, here goes pure Parameter Substitution with an empty string. Caveat is that I have defined someletters and moreletters as only characters. If they are alphanumeric, this will not work as it is.
filename=someletters_12345_moreletters.ext
substring=${filename//@(+([a-z])_|_+([a-z]).*)}
echo $substring
12345