Difference between revisions of "ReNamer:Rules:Replace"
m (general cleanup, answered the question) |
("Whole words only" documented) |
||
(27 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Go|up=ReNamer:Rules|prev=ReNamer:Rules:Remove|next=ReNamer:Rules:Rearrange}} | ||
+ | |||
== Replace Rule == | == Replace Rule == | ||
− | |||
− | The parameters are as follows: | + | [[Image:ReplaceRule.png|center]] |
+ | |||
+ | This rule removes the specified string from the name and replaces it with another string. It has options to replace the first occurrence, the last occurrence, or all the occurrences. You can replace multiple strings at a time. You can create a pattern with wildcards, so that any string that matches the pattern will be removed. | ||
+ | |||
+ | The parameters are as follows: | ||
− | {| class=" | + | {| class="wikitable" |
− | ! Parameter | + | |- |
+ | ! Parameter | ||
! Details | ! Details | ||
− | |||
|- | |- | ||
− | | Find | + | | Find |
− | | Enter the string to be replaced. | + | | Enter the string to be replaced. |
− | + | *You can enter multiple strings at a time. They will be searched & replaced in the order as they appear. Press the + button to insert a separator between two strings. Instead of pressing this button, you can also enter '''*|*''' from the keyboard. | |
− | * You can enter multiple strings at a time. Press the + button to | + | *If the name does not contain the specified string, the rule will not act on it. |
− | * If the name does not contain the specified string, the rule will not act on it. | + | *If the name contains more than one of these strings, it will replace them according to the Occurrences parameter. |
− | * If the name contains more than one of these strings, it will replace | ||
|- | |- | ||
− | | [[Image:]] button | + | | [[Image:PlusButton.png]] button |
− | | | + | | Inserts a separator ('''*|*''') sequence between two delimiter entries. (You can directly type'''*|*''' |
− | + | You can use this button in the '''Replace''' box also. In that case, the nthe entry in the '''Find''' box is replaced by the nths entry in the '''Replace''' box. (e.g. A -->A', B -->B' etc.) } | |
− | ''' | ||
− | |||
− | |||
|- | |- | ||
− | | Replace | + | | Replace |
− | | Enter | + | | Enter strings that will replace the "Find" strings. |
− | + | *Note that the number of strings (separated with '''*|*''') in "Find" and "Replace" boxes should be the same. If there is more strings in the "Find" box than in the "Replace" box the spare strings will be removed (replaced with an empty string). If there is more strings in the "Replace" box, the spare strings will be ignored. | |
− | * Note that | ||
|- | |- | ||
− | | Insert meta tag [[Image:]] | + | | Insert meta tag |
− | + | [[Image:ReNamer Insert Meta Tag Button.png]] | |
+ | | Click the button to see a list of [[ReNamer:Meta Tags|meta-tags]]. | ||
|- | |- | ||
− | | Occurrences | + | | Occurrences |
− | | In case | + | | In case that strings occur more than once in the filename, specify which occurrences should be replaced. (Options are: ''first only'', ''last only'', or ''all'') |
− | |||
|- | |- | ||
− | | Skip extension | + | | Skip extension |
− | | If this check box is | + | | If this check box is selected, the extension will be ignored by the rule. |
− | |||
|- | |- | ||
− | | Case sensitive | + | | Case sensitive |
| Will only remove a specified string from the name if the case matches exactly. | | Will only remove a specified string from the name if the case matches exactly. | ||
+ | |- | ||
+ | | Whole words only | ||
+ | | Remove the subject text only when it is whole word, not a part of another word. | ||
+ | For example, searching for "bar" would not find a match in "foobar" or "bars". | ||
|- | |- | ||
− | | Interpret symbols as wild cards | + | | Interpret symbols as wild cards |
− | | | + | | Treat certain symbols as [[#Wildcards|Wildcards]] for matching simple patterns (similar to [[ReNamer:Regular Expressions|Regular Expressions]]). |
+ | |||
+ | |} | ||
+ | |||
+ | === Wildcards === | ||
− | {| class=" | + | {| class="wikitable" |
− | ! | + | |- |
+ | ! Wildcard | ||
! Represents | ! Represents | ||
! Example | ! Example | ||
− | |||
|- | |- | ||
− | | <center | + | | <center>*</center> |
− | | any number of characters (including numbers, space, underscores, etc.). | + | | any number of characters (including numbers, space, underscores, etc.). |
| '''abc*''' equals '''abc''' followed by 0 or more characters. | | '''abc*''' equals '''abc''' followed by 0 or more characters. | ||
− | |||
|- | |- | ||
− | | <center>?</center> | + | | <center>?</center> |
− | | Any single character (including numbers, space, underscores, etc.) | + | | Any single character (including numbers, space, underscores, etc.) |
| '''ab?d''' equals '''abcd''', '''ab1d''', '''ab d''', '''ab_d''', etc. | | '''ab?d''' equals '''abcd''', '''ab1d''', '''ab d''', '''ab_d''', etc. | ||
+ | |- | ||
+ | | <center>[]</center> | ||
+ | | Brackets enclose a set of characters, any one of which may match a single character at that position. | ||
+ | | '''foo[ab]ar '''equals '''fooaar''' and '''foobar''' | ||
+ | |- | ||
+ | | <center>-</center> | ||
+ | | (only within a pair of brackets) denotes a range of characters. | ||
+ | | '''foo[a-z]ar '''equals '''fooaar''', '''foobar,''' '''foocar,''' '''foodar,''' etc. | ||
+ | |} | ||
+ | |||
+ | == Beware of conflicting replacements == | ||
+ | If you enter multiple find and replace strings they will be executed as multiple Replace rules, so first string will go first and only after replacing all (or first, or last) occurrences of that string the second string in the Find box will be searched & replaced. | ||
+ | |||
+ | {| | ||
+ | | | ||
+ | |||
+ | {| class="wikitable" | ||
+ | ! Find | ||
+ | ! Replace | ||
|- | |- | ||
− | | | + | | A*{{Pipe}}*B |
− | | | + | | B*{{Pipe}}*A |
− | | | + | |} |
+ | |||
+ | | | ||
+ | {| class="wikitable" | ||
+ | ! Name | ||
+ | ! New Name | ||
|- | |- | ||
− | | | + | | ABBA.mp3 |
− | + | | AAAA.mp3 | |
− | | | ||
|} | |} | ||
+ | |||
|} | |} | ||
+ | |||
+ | You may expect the new name to be <tt>BAAB.mp3</tt>, but it's not. This happens because first all <tt>A</tt>'s are replaced with <tt>B</tt>'s (we get <tt>BBBB.mp3</tt>) and only then all <tt>B</tt>'s are replaced with <tt>A</tt>'s (and the final result is <tt>AAAA.mp3</tt>). | ||
+ | |||
+ | If you need to apply character-to-character mappings you should use [[ReNamer:Rules:Translit|Translit rule]]. | ||
+ | |||
+ | [[Category:ReNamer]] |
Revision as of 16:11, 5 January 2021
Replace Rule
This rule removes the specified string from the name and replaces it with another string. It has options to replace the first occurrence, the last occurrence, or all the occurrences. You can replace multiple strings at a time. You can create a pattern with wildcards, so that any string that matches the pattern will be removed.
The parameters are as follows:
Parameter | Details |
---|---|
Find | Enter the string to be replaced.
|
button | Inserts a separator (*|*) sequence between two delimiter entries. (You can directly type*|*
You can use this button in the Replace box also. In that case, the nthe entry in the Find box is replaced by the nths entry in the Replace box. (e.g. A -->A', B -->B' etc.) } |
Replace | Enter strings that will replace the "Find" strings.
|
Insert meta tag | Click the button to see a list of meta-tags. |
Occurrences | In case that strings occur more than once in the filename, specify which occurrences should be replaced. (Options are: first only, last only, or all) |
Skip extension | If this check box is selected, the extension will be ignored by the rule. |
Case sensitive | Will only remove a specified string from the name if the case matches exactly. |
Whole words only | Remove the subject text only when it is whole word, not a part of another word.
For example, searching for "bar" would not find a match in "foobar" or "bars". |
Interpret symbols as wild cards | Treat certain symbols as Wildcards for matching simple patterns (similar to Regular Expressions). |
Wildcards
Wildcard | Represents | Example |
---|---|---|
any number of characters (including numbers, space, underscores, etc.). | abc* equals abc followed by 0 or more characters. | |
Any single character (including numbers, space, underscores, etc.) | ab?d equals abcd, ab1d, ab d, ab_d, etc. | |
Brackets enclose a set of characters, any one of which may match a single character at that position. | foo[ab]ar equals fooaar and foobar | |
(only within a pair of brackets) denotes a range of characters. | foo[a-z]ar equals fooaar, foobar, foocar, foodar, etc. |
Beware of conflicting replacements
If you enter multiple find and replace strings they will be executed as multiple Replace rules, so first string will go first and only after replacing all (or first, or last) occurrences of that string the second string in the Find box will be searched & replaced.
|
|
You may expect the new name to be BAAB.mp3, but it's not. This happens because first all A's are replaced with B's (we get BBBB.mp3) and only then all B's are replaced with A's (and the final result is AAAA.mp3).
If you need to apply character-to-character mappings you should use Translit rule.