perl-rename 's/b(\d{2}A)/\1/' * finds and renames every part of any file with

  1. "b" followed by

  2. 2 digits followed by

  3. "A"

Is there an option or way to make the regular expression case-insensitive, i.e. also matches either an uppercase "B" for the first part and/or a lowercase "a" for the last part?

  • 1
    Can you provide some samples? its not clear what you mean by "an uppercase "A" for the first part and/or a lowercase "a" for the last part?"
    – Inian
    May 2 '20 at 10:30
  • Is [aA] what you're looking for?
    – Kusalananda
    May 2 '20 at 10:32
  • @Kusalananda Yes. The matching works then. If you provide your comment as an answer, I can mark it as solved.
    – henry
    May 2 '20 at 10:37
  • @Inian I made a mistake with the "uppercase "A"". It should have been "B" instead. I genuinely thought the enumerated list was self-explanatory.
    – henry
    May 2 '20 at 10:38

The s/// substitution command in Perl (and thus in the Perl rename command) has a flag /i to do case insensitive match. All you need to do is

perl-rename -n 's/b(\d{2}A)/\1/i' *.jpg

Remove the -n flag when you identify the files are renamed as expected. It only does a dry-run to show how the files will be eventually renamed.

To selectively allow case insensitive matching of one or several characters, use e.g. [aA] (will match either a or A).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.