#1 : 24/07-22 17:08 Mark
Posts: 3
|
Hello guys,
I have files with version in final of the names, ex: - animation-education-app-4.3.5.zip - magazine-blog-software-1.2.3.zip I need to modify all initial text in a List Replace using wildcard (*) and keeping version unchanged. Ex (animation*...*-4.3.5.zip / magazine-*...*-1.2.3.zip ): - animation-school-education-appuniversity-4.3.5.zip - magazine-newspaper-blog-news-software-1.2.3.zip Thank you! |
#2 : 24/07-22 18:29 David Lee
Posts: 1125
|
Use a regular expression instead of a simple wildcard.
eg Replace: animation.*- with: whatever Use regular expressions This will replace everything beginning with "animation" up to and including the final instance of "-" If you always want to keep the initial word then you can use... Replace: animation\K.*- with: -school-education-appuniversity- etc In a regular expression "." matches any character and the modifier "*" is an instruction to repeat the match any number of times (including zero). The meta-character "\K" is an instruction not to include preceding matched characters in the final match. |
#3 : 25/07-22 14:51 Mark
Posts: 3
|
Reply to #2:
Thank you, man!! It Works ! But in some cases I have versions starting with a point "." instead a "-" eg: animation-school-education-appuniversity.1.2.3.zip How can I achieve the same result in this situation? |
#4 : 25/07-22 16:13 David Lee
Posts: 1125
|
Reply to #3:
Straightforward: Basically use "." instead of "-" as your separating character. However it's a bit more complicated since you will have to match the first dot in the filename and also dots appear in the version number in all filenames which would lead to unwanted results in other filenames. The solution is to match "." only if it is followed by a version number. For this we can use a "lookahead" in the regular expression" eg the expression "qwerty(?=uiop)" will match the string "qwerty" but only if it is followed by "uiop" and "uiop" will not be included in the final match. So... Replace: animation\K.*\.(?=\d?\.\d?\.\d?) with: -school-education-appuniversity. will replace "animation-education.1.2.3" with "animation-school-education-appuniversity.1.2.3" Note that "." in a regular expression indicates any character, so it has to be "escaped" as "\." in order to represent itself. You can handle cases with either "." or "-" in a single expression as follows... Replace: animation\K.*([-\.])(?=\d?\.\d?\.\d?) with: -school-education-appuniversity\1 Here the expression [abcd] will match any character appearing in the brackets and placing the expression in parenthesis (ie "([-\.])") will save the result in a numbered variable (\1), which can be used in the replacement string. |