Help moving (DATE) from front of filename to end.

A swapping-ground for Regular Expression syntax

Help moving (DATE) from front of filename to end.

Postby solozero » Wed May 27, 2020 12:46 am

Hello,

I am a new member seeking some regular expression assistance. I have thoroughly searched the forums and was unable to find my exact solution or something similar enough to hack together a solution. I am really impressed by how kind and helpful people are on this forum so I decided to make an account and see if someone here could offer some assistance to write a regular expression that takes a date at the beginning of a file name and moves it to the end.

Specifically:

Original:
(DATE) NAME

Modified:
NAME (DATE)

The date includes parenthesis and some files have (DATE-DATE)

Here's what I have so far:
MATCH: ^((\d{4}) (.*)
Replace: \2 (\1)

Currently this works only for DATE with no parentheses (most important) and it does not take into account DATE-DATE (date hyphen date) (nice to have, not necessary).

If anyone could give me any feedback on why my current code isn't working as expected or maybe point me in the right direction to get this working I would greatly appreciate it! Thank you.
solozero
 
Posts: 3
Joined: Wed May 27, 2020 12:11 am

Re: Help moving (DATE) from front of filename to end.

Postby RegexNinja » Wed May 27, 2020 8:10 am

Without examples, its hard to guess..
By (Date1-Date2) & your expression, is it safe to assume that Date1=yyyy ??
What are the possible formats for Date2 ??

To match a literal ( you can use either:.. [(] or \(
To match 0-or-more of them, use either: [(]* or \(*
The same methods can be used to match a literal )
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Help moving (DATE) from front of filename to end.

Postby solozero » Wed May 27, 2020 3:11 pm

Thanks for your reply! I should have been more specific.

Yes, date = yyyy. Example would be (2000-2005) so from this (2000) year to that year (2005).

I hope that this makes more sense?


Thanks so much for trying to help point me in the right direction. With your feedback, I've tried using
MATCH:
^(()* \d{4}) (.*)
REPLACE:
\2 (\1)

Which still doesn't seem to be working unfortunately. If I delete the parenthesis and just use:
MATCH:L
^(\d{4}) (.*)
REPLACE:
\2 (\1)
The expression works as intended except it does not recognize YYYY dates in side of parenthesis. Please advice. :)
solozero
 
Posts: 3
Joined: Wed May 27, 2020 12:11 am

Re: Help moving (DATE) from front of filename to end.

Postby therube » Wed May 27, 2020 4:34 pm

You have to escape your literal parens.
In your OP, your parens are unbalanced.

Code: Select all
Match:  ^(\(\d\d\d\d\))\s(.*)
Replace:  \2 \1

Match file names that start with paren+4 digits+closing paren, followed by a space, followed by anything else.
Then rearrange.

Actual file name examples would have been nice.
Code: Select all
(2000) so from this.mp3 ->
so from this (2000).mp3
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Help moving (DATE) from front of filename to end.

Postby solozero » Wed May 27, 2020 8:09 pm

Thank you therube. That worked perfectly! :mrgreen: I hadn't considered your method prior but it seems to obvious now. Thanks for the brief explanation! Also, apologies for not giving file names. I didn't realize that could be important to you.
solozero
 
Posts: 3
Joined: Wed May 27, 2020 12:11 am

Re: Help moving (DATE) from front of filename to end.

Postby RegexNinja » Wed May 27, 2020 10:50 pm

Solozero
If your issue is resolved, dont bother replying.
If not, you would still need to elaborate on (Date1-Date2)

You seem to be saying that Date1 could be inbetweeen 2000-2005 ??
But Ive still no idea about what Date2 could be: (-mm, -mm-dd, etc) ??

So far, nothing posted handles both names with and without parentheses.
And certainly nothing is gonna capture Date2 (if and when it actually exists) ??

Both situations are easy to accomplish, but not without answering the questions.
Either directly, or by posting OrigNames and desired-NewNames.
Cheers.
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to Regular Expressions