How to Invert file name around - ?

Bulk Rename Utility How-To's

How to Invert file name around - ?

Postby BlackFosy » Sun Mar 26, 2023 5:53 pm

Hello

Possible make this?

example

We Begin at the End - John Smith
Accidents of Marriage - Chriss Carter

want change to:
John Smith - We Begin at the End
Chriss Carter - Accidents of Marriage


Thanks
BlackFosy
 
Posts: 2
Joined: Sun Mar 26, 2023 5:49 pm

first - last ===> last - first

Postby Luuk » Sun Mar 26, 2023 7:25 pm

Greetings BlackFosy, with Regex(1) the "Match" and "Replace" can be like...
^(?!.* - .* - )(.+)( - )(.+)
\3\2\1

The red-part is a lookahead to make sure there's only one " - " inside of your filenames.
If removing it, then it would always just use the very last " - " as the separator.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to Invert ?

Postby Admin » Sun Mar 26, 2023 10:51 pm

Just to add to this, there is also the possibility to use the "Simple" option in the RegEx (1).
In that case you can use :

Match: %1 - %2
Replace: %2 - %1

****************************************************************************
More Info taken from the help file:

Bulk Rename Utility 3.4 introduces Simple Regular Expressions, which can be enabled by switching on the option Simple in group RegEx (1).
Simple regular expressions work by matching text and then removing or rearranging the matched text.

The syntax is very simple, up to 9 matching tags can be used %1, %2, %3 until %9, which match a string of text. Examples:

Match: %1-%2
Replace: %2-%1

It will match first a string of text with %1 then the character '-' and then another string of text. It will then replace it with the second string of matched text, the character '-' and the first string of text matched. Effectively it will switch text around the character '-'.

Match: %1(%2)
Replace: %2

It will match first a string of text with %1 then a '(' and then another string of text followed by ')'. It will then replace it with the second string of matched text and the rest is dropped.

Match: %1-%2-%3 %4
Replace: %3-%2-%1 %4

It will match and reorder text such as '2020-03-12 Boston' into '12-03-2020 Boston'.

Match: %1%2%3%4
Replace: ABC%4

Replaces the first 3 characters with 'ABC'.

Up to 9 matching tags can be used : %1, %2, %3 until %9.

There are also 5 additional modifiers that can be used in the Replace string when Simple is used. These 5 modifiers are the same modifiers as when Simple is not used:
\U : Causes all subsequent characters to be output in upper case, until a \E is found.
\L: Causes all subsequent characters to be output in lower case, until a \E is found.
\E : Terminates a \L or \U sequence.
\l : Causes the next character to be outputted, to be output in lower case.
\u : Causes the next character to be outputted, to be output in upper case.

Examples:
Match: %1
Replace: \U%1

Capitalizes the name because %1 matches the whole name and \U%1 capitalizes it.

Match: %1_%2
Replace: \U%1\E_%2

Capitalizes the part of the name before _.

Match: %1_%2
Replace: \U%1\E_\L%2

Capitalizes the part of the name before _ and lowercases the part of the name after _.

Match: %1%2%3%4
Replace: \L%1%2%3\E%4

Lowercases the first 3 characters of a name.
Admin
Site Admin
 
Posts: 2354
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To