Is there any implementation of regex that allow to replace group in regex with lowercase version of it?
Several answers have noted the use of \L
. However, \E
is also worth knowing about if you use \L
.
\L
converts everything up to the next\U
or\E
to lowercase. ...\E
turns off case conversion.(Source: https://www.regular-expressions.info/replacecase.html )
So, suppose you wanted to use rename to lowercase part of some file names like this:
artist_-_album_-_Song_Title_to_be_Lowercased_-_MultiCaseHash.m4a
artist_-_album_-_Another_Song_Title_to_be_Lowercased_-_MultiCaseHash.m4a
you could do something like:
rename -v 's/^(.*_-_)(.*)(_-_.*.m4a)/$1\L$2\E$3/g' *