• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Find and Replace Question

Community Beginner ,
Nov 08, 2021 Nov 08, 2021

Copy link to clipboard

Copied

Hi all,

 

I need to change the name of over 2000 images. The images end in -1 and -2 etc but I need to replace them with _1 and _2 etc. 

 

The trouble I have is that some of the file names also have a - throughout so replacing all of the - with _ doesn't work. I've found a common theme is that they all have a _ as either their second or third last character. Could somebody let me know how I may be able to adjust these all without doing it manually?

TOPICS
How to

Views

91

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 09, 2021 Nov 09, 2021

If not exactly two, but possibly one or two digits...

 

(.+)(-)(\d{1,2})(\.[^\.]+$)

 

 

 

Likes

Translate

Translate
Community Expert ,
Nov 08, 2021 Nov 08, 2021

Copy link to clipboard

Copied

In the Batch Rename dialog, one possible option using String Substitution + Regular Expression would be:

 

Find:

(.+)(-)(\d+)(\.[^\.]+$)

Replace:

$1_$3$4

 

regex-rename.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

This is almost perfect. Thank you.

 

Is there a way to restrict it to changing the _ only if there are 2 characters after it? 

 

An example of a file I don't want changed: BA-48807 (this is the full name of the file and needs to remain the same).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Certainly:

 

(.+)(-)(\d{2})(\.[^\.]+$)

 

P.S.: BA-48807 should not have been affected, at least it wasn't in my tests...

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Beautiful, I apologise for not being clear, I meant up to 2 characters haha. 

 

So for example. File names that should be changed (> what they should be changed to):

 

ABCD-1 > ABCD_1

ABCD-12 > ABCD_2

 

File names that should not be changed:

 

ABCD-123

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

If not exactly two, but possibly one or two digits...

 

(.+)(-)(\d{1,2})(\.[^\.]+$)

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

LATEST

Wonderful! This is perfect. Thank you so much!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines