File Automator - Rename Capabilities

553 views
Skip to first unread message

Gregory Munson

unread,
Sep 9, 2023, 2:13:34 PM9/9/23
to OneCommander
I have a bunch of files that have a date imputed into them that I want to remove. There is no documentation as of yet for this feature.

File Example:
report-10-19-2016 (2016_10_19 22_30_40 UTC).xls

Results I Hope to Achieve:
report-10-19-2016.xls

These files were from an old Windows Backup tool that no longer exists to retore them and it would remove those date and yes the files are raw not compressed by the backup utility tool.


Thanks for you time...

OneCommander Support

unread,
Sep 9, 2023, 2:50:23 PM9/9/23
to OneCommander
It is hard to make documentation for Regex as it is complex, but there is a ton of resources about it.
The other rules should be self explanatory with additional information on mouse over the text input boxes.

ChatGPT can help writing regex
"I have a text: report-10-19-2016 (2016_10_19 22_30_40 UTC).xls and would like a regex rule to remove everything in () including brackets"

In rule select Regex Replace and paste:
\s?\(.*?\)

I just added \s? in the beginning
\s? is to remove any space if there is one before the (

As ChatGPT explains:
  1. \(: This part of the regex matches an open parenthesis ( character. The backslash \ is used to escape the parenthesis because parentheses are special characters in regex. So, \( is used to specifically match an open parenthesis.

  2. .*?: This part of the regex uses .*? to match any characters (even zero characters) non-greedily within parentheses.

    • . (dot): In regex, the dot . is a special metacharacter that matches any character except for a newline character. In this context, it matches any character within the parentheses.

    • * (asterisk): The asterisk * is a quantifier in regex, and it means "zero or more occurrences of the preceding element." In this case, the preceding element is . (any character), so .* matches zero or more characters within the parentheses.

    • ? (question mark): The question mark ? makes the preceding quantifier * non-greedy. In a non-greedy or lazy match, the quantifier will match as few characters as possible while still allowing the overall pattern to match. Without ?, it would be greedy and match as many characters as possible.

  3. \): This part of the regex matches a closing parenthesis ) character. Like with the open parenthesis, the backslash \ is used to escape the parenthesis to specifically match a closing parenthesis.

So, when you put it all together, \([^)]*\) matches a pattern that starts with an open parenthesis, then matches any characters (even zero characters) non-greedily within parentheses, and finally ends with a closing parenthesis. This effectively captures everything within a pair of parentheses, including the parentheses themselves.


OneCommander Support

unread,
Sep 9, 2023, 2:53:22 PM9/9/23
to OneCommander
PS: Pasting the explanation again as it doesn't allow editing of the broken formatting:

 let's take a detailed look at the regular expression \([^)]*\):


\(: This part of the regex matches an open parenthesis ( character. The backslash \ is used to escape the parenthesis because parentheses are special characters in regex. So, \( is used to specifically match an open parenthesis.

.*?: This part of the regex uses .*? to match any characters (even zero characters) non-greedily within parentheses.

. (dot): In regex, the dot . is a special metacharacter that matches any character except for a newline character. In this context, it matches any character within the parentheses.

* (asterisk): The asterisk * is a quantifier in regex, and it means "zero or more occurrences of the preceding element." In this case, the preceding element is . (any character), so .* matches zero or more characters within the parentheses.

? (question mark): The question mark ? makes the preceding quantifier * non-greedy. In a non-greedy or lazy match, the quantifier will match as few characters as possible while still allowing the overall pattern to match. Without ?, it would be greedy and match as many characters as possible.

\): This part of the regex matches a closing parenthesis ) character. Like with the open parenthesis, the backslash \ is used to escape the parenthesis to specifically match a closing parenthesis.

OneCommander Support

unread,
Sep 9, 2023, 2:55:46 PM9/9/23
to OneCommander
PS2: ChatGPT sometimes messes up. Both regexes work but the first one I pasted makes more sense, so just ignore the first line

Gregory Munson

unread,
Sep 9, 2023, 6:34:35 PM9/9/23
to OneCommander
Thanks,

The  \s?\(.*?\) is exactly what I was looking for.
Reply all
Reply to author
Forward
0 new messages