#1 2021-02-01 18:10

koolestani
Member
Registered: 2020-04-26
Posts: 9

How to bring Year "component" to the front/beginning of file name?

Hey there,
I have some file names in the following pattern:
Some Name (2010)
Some Bigger Name (2013)
Name (2015)

This is what they should look like after renaming:
(2010) Some Name
(2013) Some Bigger Name
(2015) Name

So I was trying to shift the Year part to the beginning of these file names, and reg ex is just too much for me
I tried these expressions to be replaced with $2\ $1, with no luck

(.+?)\ (\d{4})
(.*?)\ (d{4})

This is very similar to a topic i posted earlier so i thought i could figure it out by myself but unfortunately that didn't happen.
The basic difference between that topic and this one is:
Earlier it was periods (.) and YY.MM.DD format.
This time it is spaces ( ) and YYYY format.

Thanks in advanced for helping my noob self out.

Offline

#2 2021-02-01 20:01

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 353

Re: How to bring Year "component" to the front/beginning of file name?

Hi,

koolestani wrote:

(.+?)\ (\d{4})
(.*?)\ (d{4})

You were close. Parenthessis in RegEx are used to capture groups so you missed escape character to make them literal like \( and \)
Also we need to put captured group (yyyy) on the beginning of the string and to capture part before it and switch their places, like you did just without \ in replace box. So it looks like:

1) Regular Expressions: Replace expression "(.+) (\(\d{4}\))" with "$2 $1" (skip extension)

You can debug RegExes using various online tools which explains typed expression like https://regexr.com/5lg2h


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#3 2021-02-01 22:40

koolestani
Member
Registered: 2020-04-26
Posts: 9

Re: How to bring Year "component" to the front/beginning of file name?

Thanks for the help
This works indeed.
And to reverse the effect ((2010) Some Name back to Some Name (2010)) the following works perfectly as well

Regular Expressions: Replace expression (\(\d{4}\)) (.+) with $2 $1  (skip extension)

Last edited by koolestani (2021-02-01 22:43)

Offline

Board footer

Powered by FluxBB