Space before bracket

Advanced Renamer forum
#1 : 28/08-20 04:37
Rich
Rich
Posts: 8
I have a large number of files that need a space added before the bracket, such as:
An Act of War(2015) changed to An Act of War (2015)

Can anyone help with the script?
Thanks
Rich


28/08-20 04:37
#2 : 28/08-20 07:58
David Lee
David Lee
Posts: 1125
RTFM!!!

Hint: You want to replace a parenthesis with a space followed by a parenthesis.


28/08-20 07:58
#3 : 28/08-20 14:33
Rich
Rich
Posts: 8
Reply to #2:

Thanks. Please be kind to my ignorance...i have been trying to read the manual. The issue that in the long list of file names, not all need the correcting so I want it to apply to only those that don't have a space. That is where I am stuck.


28/08-20 14:33 - edited 28/08-20 15:01
#4 : 28/08-20 15:13
David Lee
David Lee
Posts: 1125
Reply to #3:
It's helpful if you define the problem properly when you post a question!

Use the Replace method with a regular expression and replace "not space" + (" with "space" + "("

Replace: "[^ ]\("
With: " ("
Use regular expressions

See www.advancedrenamer.com/user_guide/regular_expresions


28/08-20 15:13
#5 : 28/08-20 16:38
Rich
Rich
Posts: 8
Reply to #4:

Great thanks! Worked perfectly. I also understand more now...


28/08-20 16:38
#6 : 29/08-20 21:36
Rich
Rich
Posts: 8
Reply to #5:

Actually I think it may have created the space required, but while doing so, also remove the last letter of the preceding file name. Is that possible?


29/08-20 21:36
#7 : 30/08-20 00:24
Bruno G.
Bruno G.
Posts: 6
Reply to #6:

It depends on the Regular Expression used in the "Replace" field. This could happen if there was a dot '.' at the beginning.

Regular Expressions are really powerful but can be hard to understand. This online tool helped me tremendously in understanding/testing them : regexr.com


30/08-20 00:24 - edited 30/08-20 00:25
#8 : 30/08-20 19:09
Rich
Rich
Posts: 8
Reply to #7:

As I suspected, the script words by creating a space, but at the same time it is resulting in deleting the last letter:

A Perfect Getaway(2009) is becoming
A Perfect Getawa (2009)

Thanks to all that have taken the time to assist and for the links, I'll continue to research and try to find the solution.


30/08-20 19:09 - edited 31/08-20 03:27
#9 : 31/08-20 08:52
David Lee
David Lee
Posts: 1125
Reply to #8:
Sorry - my fault!

Try the regex [^ ]\K\(

Adding "\K" will remove any preceding matched characters from the final match so only the "(" will be replaced by " (".

Note that "\K" isn't included in Kim's introduction to regular expressions. Another solution, based on the information in his basic introduction, would be...

Replace: ([^ ])(\()
With: \1 \2


31/08-20 08:52
#10 : 01/09-20 16:26
Rich
Rich
Posts: 8
Reply to #9:

Worked like a charm. Thanks.

For reference, does the K represent any letter?


01/09-20 16:26
#11 : 01/09-20 17:40
David Lee
David Lee
Posts: 1125
Reply to #10:
No - \K doesn't represent anything. It is simply an instruction to forget anything matched up to this point so that it isn't included in the final match returned by the regular expression.

For example: in your case we want to match any character that is not a space ( ie "[^ ]") followed by a parenthesis but we only want to replace the parenthesis (by a space followed by a parenthesis).
As you found: "[^ ]\(" will match "y(" in "Getaway(2009)" so the Replace method will return "Getawa (2009)". Adding "\K" means that the "y" is 'forgotten' in the match so that only the parenthesis is replaced with " (", as required.

Incidentally "(" has special meaning in a regular expression (along with several other control characters) and adding a backslash to such characters "escapes" the special meaning such that "\(" represents the character "(" itself. In other cases (such as "K"), where the character retains its usual textual meaning by default, the "escape" character indicates that it should instead be interpreted as a control character.

Hope that's helpful.


01/09-20 17:40 - edited 01/09-20 17:43