regex implementation to replace group with its lowercase version

前端 未结 6 1229
南方客
南方客 2020-12-14 14:03

Is there any implementation of regex that allow to replace group in regex with lowercase version of it?

6条回答
  •  有刺的猬
    2020-12-14 14:27

    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' *
    

提交回复
热议问题