I'm pretty familiar with regular expressions in various contexts, but bash substring matching just baffles me. Can someone please explain them to me, ideally with some examples? The examples I've found on google are very simple, and suggest pretty generic (if limited) regex matching, but when I try to use them in practical situations it never works. From my understanding substring matching should work as follows:
result=${string##pattern}
will find the longest substring of 'string', starting from its beginning, that matches 'pattern'. It removes that match from 'string' and puts the remainder in 'result'. But consider:
temp=${myvar##[^0-9]*} && echo $temp
As far as I can tell, my pattern should match 'zero or more characters that are not digits' - the longest such match from the start of the string. Then take as example:
myvar=my_file_123_45.txt
I should expect the characters 'my_file_' to be matched: that is the longest combination of characters from the start of 'string' that aren't digits. Instead, the returned result is empty! Everything gets matched! What happened to excluding digits?! In both gedit (using the search-and-replace regex engine), and in Labview's regex tools, the match pattern
pattern=^[^0-9]*
which i believe to be equivalent, results in my expected match - 'my_file_'. What's different about Bash?