Skip to main content
Participant
December 9, 2024
Question

change the first character in file name

  • December 9, 2024
  • 2 replies
  • 355 views

Hey folks.

I have big data base with specific file names.

Example

w=xxx-sometext-sometext-sometext-sometext_.tif

w=xxxxxx-sometext-sometext-sometext-sometext_.tif

Numbers of x are different. I want to only change the first - to _ like below

w=xxx_sometext-sometext-sometext-sometext_.tif

 

How to do this?

 

 

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
December 10, 2024

@dawidc21191320 

 

As long as you untick the "Replace all" then only the first match will be replaced.

 

Inspiring
December 9, 2024

Assuming the file names only have numbers at the beginning, you can use this regex to match only the dash after a number:

(?<=\d\d)-

 You can use this in the batch rename tool with the string substitution option and the "use regular expression" box checked.

If your filenames can also have numbers in the middle and you don't want to replace the dashes after those, it's a bit more complicated because in Regex, lookbehinds (something that looks backwards in the string without selecting those characters) need to have a fixed length. So, you're going to need multiple instances of this string substitution, each with a different number of "\d"s in them - these match individual digits.

// matches only a dash that comes after the start of the string followed by 1 digit
(?<=\A\d)-
// matches only a dash that comes after the start of the string followed by 2 digits
(?<=\A\d\d)-
// matches only a dash that comes after the start of the string followed by 3 digits
(?<=\A\d\d\d)-

// etc...

 Hope this helps!