Extract and move numbers within the file name

A swapping-ground for Regular Expression syntax

Extract and move numbers within the file name

Postby FireHawk » Wed Jan 28, 2015 11:04 pm

Hello! I am new to RegEx. I'm trying to extract a set of numbers from the middle of each file name and move them to be the first characters of the renamed file. All of the numbers should have three digits after moving - 000 format.
I'd like to turn file names like these:
File Name Sample 001 - March 2014.pdf
FileName Sample 45 - February 2015.pdf
FileName 647 - January 2013.pdf


Into these:
001 File Name Sample - March 2014.pdf
045 FileName Sample - February 2015.pdf
647 FileName - January 2013.pdf


I appreciate any help you can offer!
FireHawk
 
Posts: 3
Joined: Wed Jan 28, 2015 7:25 pm

Re: Extract and move numbers within the file name

Postby Admin » Sat Jan 31, 2015 12:21 am

Difficult one! Are the numbers ALWAYS before the - with a space on left and right of the number?
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Extract and move numbers within the file name

Postby FireHawk » Sun Feb 01, 2015 2:06 am

Yes, the format has a leading space and a trailing space after the number 100% of the time.
FireHawk
 
Posts: 3
Joined: Wed Jan 28, 2015 7:25 pm

Re: Extract and move numbers within the file name

Postby Admin » Mon Feb 02, 2015 7:55 am

You could use:
Match:: (.*) (.*) - (.*)
Replace: \2 \1 - \3

That would result in :

001 File Name Sample - March 2014.pdf
647 FileName - January 2013.pdf
45 FileName Sample - February 2015.pdf

Then in a second pass you could padding the numbers with zeros (See other topics on this forum)

thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Extract and move numbers within the file name

Postby FireHawk » Mon Feb 02, 2015 4:49 pm

by Admin » Mon Feb 02, 2015 12:55 am
You could use:
Match:: (.*) (.*) - (.*)
Replace: \2 \1 - \3


This worked PERFECTLY! Thank you so very much for your help. This tool and this little bit of code will save me hours of work!
FireHawk
 
Posts: 3
Joined: Wed Jan 28, 2015 7:25 pm

Re: Extract and move numbers within the file name

Postby Admin » Mon Feb 02, 2015 11:18 pm

That's great! :)
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Extract and move numbers within the file name

Postby WanderMax » Mon Feb 09, 2015 9:28 am

Admin wrote:That's great! :)


Hi
I found that you app (2.713 x64) can not match file name in the unicode words , like chinese or japanese ones in the regular expression function.
Here is the example :

????? - Yes!!.cue
????? - Yes!!.flac
????? - Yes!!.log
===>
Yes!! - ?????.cue
Yes!! - ?????.flac
Yes!! - ?????.log

Match :(.*) - (.*)
Replace :\2 - \1
Nothing worked!!
I hope you can check and fix this issue!!!

Your forum can not support unicode strings, it becomes "???" in this thread~~
I upload it into cloud
http://pan.baidu.com/s/1i3KNkWl

PS : Is it possible to add new features in your next version?? Like custom the column, more language support??
Thanks again.
WanderMax
 
Posts: 6
Joined: Mon Feb 09, 2015 9:15 am


Return to Regular Expressions