Syntax for renaming files

A swapping-ground for Regular Expression syntax

Syntax for renaming files

Postby konarktriv7 » Sun Jul 26, 2020 11:42 am

I have many files which contain the syntax below:

All files contain random text as filename but they all end with the syntax like m01-1 to m01-20 and then m02-01 to m02-15, m03-1 to m03-12

I would like to order them by adding a number in front of it.
It would be fine if the files starting with m01-1 to m01-20 would be numbered for example like
011 to 0120 (followed by the file name)

And the m02 series would be 021 to 0215

As long as the files will be in the correct order when sorting them.

Any suggestion how to do this ?
konarktriv7
 
Posts: 1
Joined: Sun Jul 26, 2020 11:40 am

Re: Syntax for renaming files

Postby therube » Sun Jul 26, 2020 12:03 pm

Your examples seem "haphazard", in that in one place you show -1, in another -01.
Not sure if that is the way it is or a typo...?


1:RegEx
Code: Select all
Match:  (.*)(m\d\d-)(.*)
Replace:  \1\20\3


Match everything
Up to the final m{digit}{digit}{dash}
Match everything else

Copy all as is, except add a '0' after the {dash}

---

Ah, reading it again, I think I was totally misunderstanding what you wanted.

---

Test with this, ensuring it is what you wanted, working as expected.

1:RegEx
Code: Select all
Match:  (.*)(m)(\d+)-(\d+)(.*)
Replace:  \3-\4 - \1\2\3-\4\5


Match everything
Up to the final m{digits}{dash}{digits}
Match everything else

Concatenate the two sets of {digits}
move them to the beginning of the name
add a dash in there for readability
Copy the original name, as it was
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions


cron