Removing the string "_#####" from the middle of file names

A swapping-ground for Regular Expression syntax

Removing the string "_#####" from the middle of file names

Postby x30Jx » Fri Jun 13, 2014 10:20 pm

File names are of random length, and the number of digits in the _<numbers here> string is arbitrary, but right now, between 1 and 7 digits.

All files are currently in the form: <Number I want to keep>_<Usless ID Ref>(Real ID I need to keep).ext

eg: 123-ABC_98765(Type-A).pdf. I need it to be 123-ABC (Type A).pdf. I have thousands of files to perform this rename on.

I am not strong at regular expressions at all; I don't even know if they might be used here. Any direction would be greatly appreciated.
x30Jx
 
Posts: 2
Joined: Fri Jun 13, 2014 9:27 pm

Re: Removing _#'s from middle of orignames

Postby truth » Sat Jun 14, 2014 7:26 am

To remove all consecutive-digits following _
(.+)_\d+(.+)
\1\2

To remove a max of 7-digits following _
(.+)_\d{1,7}(.+)
\1\2

Both expressions remove the last occurence of _## within OrigNames
Neither will remove _## from the very beginning/end of OrigName
If that functionality is needed, change .+ into .*

Going by your example NewName, you prob want a space inbetween \1 and \2
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay

Re: Removing the string "_#####" from the middle of file names

Postby x30Jx » Sat Jun 14, 2014 4:58 pm

You just saved me about 8 hours of work. And the .+ (last occurence) is exactly what I needed anyway (over .*) Thank you so much!
x30Jx
 
Posts: 2
Joined: Fri Jun 13, 2014 9:27 pm


Return to Regular Expressions