开发者

Some simple regex for renaming files

开发者 https://www.devze.com 2023-04-03 19:13 出处:网络
I have a naming convention on a bunch of files that I\'d like to change, so I\'m using the program Metamorphose. It uses Regex to select files and selectively changes parts of filenames based on repla

I have a naming convention on a bunch of files that I'd like to change, so I'm using the program Metamorphose. It uses Regex to select files and selectively changes parts of filenames based on replace using regex.

I've been having a bit of a problem replacing one part of my file names (I managed it last night, but forgot what I typed). Basically I want to target everything after ")-" and wipe it.

For example: "IMG2061211-(2011.09.08)-shot for web" I would like to target "shot for web" and get rid of it. This value changes and has numbers sometimes.

I was able to select all the files by using (?:\)-)+.* but I've since been unable to select the ending part to replace with nothing.

Edit for specificity:

I've basically been running through the file names a few times each to replace different parts and was wondering if there was a better way to go about doing it.

An example of the file name is: Verdrahtung-Fibre_Optik-(RR01612)-XVF221-2011 What I'm trying to achieve is something less silly. I just want to achieve Verdrahtung - Fibre Optik [RR01612]

I've been doing it stepwise, using \)-.* to get rid of )- and replace it with ]. I then use \( to get rid of -( and replace it with [. I then null out any _.

开发者_运维问答Is there a better way to go about doing this?


You can search for \)-.* and replace with ).

This will remove everything after the first )- in your filename.

If Metamorphose supports lookaround assertions, you can be a bit safer if you search for

(?<=\))-(?:(?!\)-).)*

and replace with nothing. This will remove everything after the last )- in your filename.

Edit: As for your example, you can search for

(.*)-\(([^)]*)\)-.*

and replace that with

$1 [$2]

(if that doesn't work, try \1 [\2]). This will change Verdrahtung-Fibre_Optik-(RR01612)-XVF221-2011 into Verdrahtung-Fibre_Optik [RR01612]. Replacing the underscores with spaces must be done in a second step unless there is always exactly one underscore.


^([^\)]+)-(.*)$ Then \1 gives 'IMG2061211-(2011.09.08)' and \2 gives 'shot for web'.

Also, check out Regex Tester.


http://regexrenamer.sourceforge.net/

Try this, this will solve all the majoe regex patterns

0

精彩评论

暂无评论...
验证码 换一张
取 消