Moving around digits in date for filename

A swapping-ground for Regular Expression syntax

Moving around digits in date for filename

Postby petermalling » Sat Apr 29, 2017 12:53 am

Which reg. expression would change filenames with this format:

Video 10-08-2015 19.08.50

to this:
2015-08-10-190850

Thanks so much in advance to anybody who has the programming skills that I obviously lack!

BR Peter.
petermalling
 
Posts: 5
Joined: Sat Apr 29, 2017 12:49 am

Re: Moving around digits in date for filename

Postby KenP » Sat Apr 29, 2017 1:45 am

This should work.

RegEx (1)
Match: ^(\d{2})-(\d{2})-(\d{4})\s([^.]*).([^.]*).([^.]*)$
Replace: \3-\2-\1-\4\5\6
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: Moving around digits in date for filename

Postby petermalling » Sat Apr 29, 2017 10:26 am

Wow - this is amazing! Thanks a lot!
I had to remove the ^ (it wouldn't change anything when it was there) - but now it works like a charm!!!
Magic!

Looking at it I can to some extent understand the logic in the expressions. Is there a really simple introduction to such expressions - without having to learn the whole Perl programming language?

BR Peter.
petermalling
 
Posts: 5
Joined: Sat Apr 29, 2017 12:49 am

Re: Moving around digits in date for filename

Postby KenP » Sat Apr 29, 2017 11:55 am

I'm sorry about the ^, to be honest I completely ignored the fact that "Video " was at the start of the file name :oops:

Maybe I should have gone to Specsavers after-all :lol:

You don't have to learn Perl to learn the regEex that's used in BRU, if you open the help file and check out "Additional Features / Regular Expressions" you'll get a good start to using regex and there's a link to a site that goes into more detail.
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: Moving around digits in date for filename

Postby petermalling » Sun May 28, 2017 9:52 pm

I am now trying out on my own, but I can't get it to work.

I want to convert
20130723_181726.jpg
to
2013-07-23-181726.jpg

I've tried this:
match: ^(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})$
replace: \1-\2-\3-\4\5\6

...but it just returns an empty string (new filename: .jpg)

I also tried to remove ^and $, but no difference.

What am I doing wrong?
petermalling
 
Posts: 5
Joined: Sat Apr 29, 2017 12:49 am

Re: Moving around digits in date for filename

Postby KenP » Sun May 28, 2017 10:35 pm

That's odd because I've just copy and pasted your regex and it works for me.

I can't get it to an empty string but here's a couple of ideas you could try,
  • Check that "Include Ext." (under the Replace box) is not checked.
  • On the menu bar check that "Renaming Options / Ignore / File Extensions" is not checked.

By the way the last part of your regex after the date could be slimmed down to _(.*) and the Replace \1-\2-\3-\4
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: Moving around digits in date for filename

Postby petermalling » Sun May 28, 2017 10:53 pm

Thanks so much for this. None of these are checked, but now that I know that the Regex is indeed correct I will try to see what could be the problem elsewhere.

Also thanks for pointing out that I could optimise the statement by taking the time as one part.

BR Peter.
petermalling
 
Posts: 5
Joined: Sat Apr 29, 2017 12:49 am


Return to Regular Expressions