Regex to replace digit dash not working

A swapping-ground for Regular Expression syntax

Regex to replace digit dash not working

Postby rickkirch » Thu Nov 17, 2016 9:41 pm

Hey folks,
I have been struggling with this for a few hours now, and i don't think it actually works. I finally took the advice of the Regex forum sticky and downloaded Regex Coach.
Regex Expression: [0-9]-
Original file name (Target string in Regex Coach): Two And A Half Men - Season 4 1-1.mp4
Replace: Episode 0
Desired file name: Two And A Half Men - Season 4 Episode 01.mp4

Regex Coach highlights the 1- at the end (as it should). Bulk Rename has a new name of: Episode 0.mp4

I don't understand what i am doing wrong. Any help?
rickkirch
 
Posts: 3
Joined: Thu Nov 17, 2016 9:32 pm

Re: Regex to replace digit dash not working

Postby KenP » Thu Nov 17, 2016 10:09 pm

I've never used it so I could be wrong, but as far as I'm aware Regex Coach isn't compatible with the Regex used in BRU, certainly the Regex Expression [0-9]- by itself will not give you the desired name change.

I'm not sure which of the 2 last digits represents the episode number so use whichever regex expression is suitable.

If the last digit in the file name (the one coloured red 1-1) is the one you want to keep this should work.
RegEx (1)
Match: (.+Season \d ).*(\d)$
Replace: \1 Episode 0\2

If it's the first of the 2 digits (the one coloured red) 1-1 you want to keep try this
RegEx (1)
Match: (.+Season \d).*(\d)-\d$
Replace: \1 Episode 0\2
KenP
 
Posts: 196
Joined: Sat Jul 30, 2016 11:25 am

Re: Regex to replace digit dash not working

Postby rickkirch » Thu Nov 17, 2016 10:44 pm

Thanks Ken,
I was reading this quote from the sticky:
"I would strongly recommend the Regex Coach as it gives you an excellent demonstration of the components in your expression."

Your first regex was the most appropriate as it removed the 1- and left the last digit. Now I have this problem:

My example only included the first item. but it runs from 1 to 26 so...

Two And A Half Men - Season 4 1-1.mp4
Two And A Half Men - Season 4 2-2.mp4
...
Two And A Half Men - Season 4 3-10.mp4
Two And A Half Men - Season 4 4-11.mp4

So if i use your regex it removes the 1- or 2- or whatever-(that is perfect). then it adds a 0 to 1 through 9 (again perfect). but the items with 2 digits (which we would want to leave alone), are reformatted to 01, 02, etc. How would you say, last digits have leading zero unless there are two digits or more?

Thanks again,
Rick
rickkirch
 
Posts: 3
Joined: Thu Nov 17, 2016 9:32 pm

Re: Regex to replace digit dash not working

Postby KenP » Thu Nov 17, 2016 11:50 pm

I think your best bet is to filter the files.

To filter the files 0-9.
Filter (12)
Mask: .*-\d\b
RegEx
Apply the RegEx expression in my previous post.


To Filter the episodes 10 and above.
Filter (12)
Mask: .*-\d{2}\b
RegEx

Apply the RegEx expression in my previous post but delete the 0 from the Replace (\1 Episode 0\2 >>> \1 Episode \2)
KenP
 
Posts: 196
Joined: Sat Jul 30, 2016 11:25 am

Re: Regex to replace digit dash not working

Postby rickkirch » Fri Nov 18, 2016 12:17 am

Thanks Ken, I will add that i had to add the {2} to the original match: (.+Season \d ).*(\d{2})$

I appreciate the help.
rickkirch
 
Posts: 3
Joined: Thu Nov 17, 2016 9:32 pm

Re: Regex to replace digit dash not working

Postby KenP » Fri Nov 18, 2016 12:52 am

rickkirch wrote:Thanks Ken, I will add that i had to add the {2} to the original match: (.+Season \d ).*(\d{2})$

ooops I overlooked that :oops:
KenP
 
Posts: 196
Joined: Sat Jul 30, 2016 11:25 am


Return to Regular Expressions