You are not logged in.
PROBLEM: We need to search with a wildcard, but have the string, found by the wildcard in the search, preserved as part of the resulting filename. We also need to convert text month names to standard numbers.
OBSERVATIONS: Being somewhat new to ReNamer, we are not sure how to accomplish this task. We do see that there is a '$n' wildcard referred to as a 'BackReference' in the rules dialog for replacements. Unfortunately, we can find no reference to this parameter in the User Manual. What we were wondering is if the '$n' wildcard provides a variable that could be used to re-incorporate the source wildcard string into the resulting filename?
EXAMPLE: When renaming files, we often need to convert 1-digit entries, used for months or days in a filename date, to a 2-digit representation of the month or day by adding a leading '0' only to 1-digit months and days. Filename dates are listed by year, month, and day as in the example below:
Update 2019-3-2 .pdf would result in Update 2019-03-02 .pdf
Update 2019-3-02 .pdf would result in the same.
Update 2019-03-2 .pdf would result in the same.
Update 03-2-2019 .pdf would result in the same.
Update 2019-03-02 .pdf would result in the same.
Update March 3 2019 .pdf would result in the same.
What rule would accomplish these tasks? Thank you for any assistance.
Last edited by LemonPeeler (2019-03-06 00:47)
Offline
Hi and welcome.
I will look later on into this. But so long a little explanation..
'$n' refers to 'BackReference' of RegularExpression search&replace,
where you can group a search pattern in parentheses (...) and reuse --what was matched and stored-- later on in replacement.
'$n' would then be used in form of '$1', '$2', '$3',... and so on till '$9', counted the opening parentheses '(' from the left of the search string.
Example on string "Vacation 2019.ext" >> search "^(\w+) (\d+)\.(\w\w\w)" >> replace "$2 - $1.$3) >> Result "2019 - Vacation.ext"
- - -
EDIT:
Ah, you talked about the Replace-Rule. So I will add another explanation....
Replace-Rule
http://www.den4b.com/wiki/ReNamer:Rules:Replace
Wildcards
Replace found wildcards with '$n' as 'Backreferences'
If you search with wildcards '?' or '*', you can use what is found in search, in the replacement by using '$n' variables.
The 'n' in '$n' represents the counter as digit, counted from the left as you have used wildcards.
For the first used wildcard it's '$1' in the replacement, for the second it's '$2'...
For example
on "ReNamer.exe",
Find: r?n*
Replace: -$1-$2-
[x] Interpret symbols as wild cards
will result in: "-e-amer-.exe"
Explanation: the '?' will find the first 'e' of "ReNamer" (as searched between 'r' and 'n'),
and the '*' find the rest after the 'n' till the end, resulting in 'amer'.
(See again > http://www.den4b.com/wiki/ReNamer:Rules … Wildcards)
On "Vacation 2019.txt"
Find: * *
Replace: $2 - $1
[x] Interpret symbols as wild cards
will result in "2019 - Vacation.txt"
Explanation:
the '*' will find any amount of signs and store them in $1,
but stops on next space, as we wanted to find a space next,
followed by another '*', now stored in $2.
In this simple constellation this will work fine, and the two parts are swapped
and a hyphen is added in between as we told so in the replacement.
HTH?
Last edited by Stefan (2019-03-06 16:51)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
First "sledgehammer" idea.
Add a zero to single digits
FROM:
Updat1 2019-03-02.pdf
Updat2 2019-03-2.pdf
Updat3 2019-3-02.pdf
Updat4 2019-3-2.pdf
Update 03-2-2019.pdf
Update March 3 2019.pdf
TO:
Updat1 2019-03-02.pdf
Updat2 2019-03-02.pdf
Updat3 2019-03-02.pdf
Updat4 2019-03-02.pdf
Update 03-02-2019.pdf
Update March 03 2019.pdf
Rule:
------ match -------------search -------replace with
1: HyphenDigitHyphen -(\d)- -0$1-
2: HyphenDigitSpace -(\d\s) -0$1
3: HyphenDigitEND -(\d)$ -0$1
4: SpaceDigitHyphen (\s)(\d-) SPACE 0$1
5: SpaceDigitSpace \s(\d\s) SPACE 0$1
So USE this rules:
1) Regular Expressions: Replace expression "-(\d)-" with "-0$1-" (skip extension)
2) Regular Expressions: Replace expression "-(\d\s)" with "-0$1" (skip extension)
3) Regular Expressions: Replace expression "-(\d)$" with "-0$1" (skip extension)
4) Regular Expressions: Replace expression "\s(\d-)" with " 0$1" (skip extension)
5) Regular Expressions: Replace expression "\s(\d\s)" with " 0$1" (skip extension)
or as Preset:
ReNamer\Presets\AddZeroToSingleDigits.rnp
(see http://www.den4b.com/wiki/ReNamer:Using_presets)
[Rule0]
ID=RegEx
Config=EXPRESSION:%2D%28%5Cd%29%2D;REPLACE:%2D0%241%2D;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1
[Rule1]
ID=RegEx
Config=EXPRESSION:%2D%28%5Cd%5Cs%29;REPLACE:%2D0%241;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1
[Rule2]
ID=RegEx
Config=EXPRESSION:%2D%28%5Cd%29%24;REPLACE:%2D0%241;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1
[Rule3]
ID=RegEx
Config=EXPRESSION:%5Cs%28%5Cd%5Cs%29;REPLACE:+0%241;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1
[Rule4]
ID=RegEx
Config=EXPRESSION:%5Cs%28%5Cd%2D%29;REPLACE:+0%241;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1
At least, this and similar rules should work for you, based on your provide examples.
But there must be a more simpler, more common way,... but I have no time right now to resolve this.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
>> "We also need to convert text month names to standard numbers."
Now I had time to see this part of your question.
You could use additional rule "Translit", see http://www.den4b.com/wiki/ReNamer:Rules:Translit
Just create an text file in the "Translits" folder like this months.txt
Jan=01
Feb=02
March=03
Apr=04
...
...
...
and add this Translit as additional rule.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Why make it complicated?
Why not use the built in capability designed for such tasks, i.e. Padding and Reformat Date rules?
Rules:
1) Padding: Add zero padding to length 2, skip extension
2) Reformat Date: Convert to "yyyy-mm-dd" from "mmmm dd yyyy", whole words only, skip extension
3) Reformat Date: Convert to "yyyy-mm-dd" from "dd-mm-yyyy", whole words only, skip extension
Input and output:
Update 2019-3-2.pdf -> Update 2019-03-02.pdf
Update 2019-3-02.pdf -> Update 2019-03-02.pdf
Update 2019-03-2.pdf -> Update 2019-03-02.pdf
Update 03-2-2019.pdf -> Update 2019-02-03.pdf
Update 2019-03-02.pdf -> Update 2019-03-02.pdf
Update March 3 2019.pdf -> Update 2019-03-03.pdf
Here is a demo:
Offline
Always that new stuff. We did not have that kind of stuff before...
Thank you for reminding us on this!
>> "1) Padding: Add zero padding to length 2, skip extension"
Will also modify other parts of the name string, like my "Updat1" to Updat01
but working fine on the provide examples.
But several "Reformat Date"-rules instead working great, even with other digits in name:
1) Reformat Date: Convert to "yyyy-mm-dd" from "yyyy-m-d", whole words only, skip extension
2) Reformat Date: Convert to "yyyy-mm-dd" from "yyyy-mm-d", whole words only, skip extension
3) Reformat Date: Convert to "yyyy-mm-dd" from "yyyy-m-dd", whole words only, skip extension
Great tool, that ReNamer.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Thank you to both Den4b Administrator and Stefan for your solutions! We are gaining a real appreciation for the flexibility of this tool and hope this question will help others better utilize its features! Thank you so much.
Offline