GP SoftwareTwitter
Opus FAQsManualCommandsObjects

A few advanced RegExp Renames

commands
regex

#1

Note for Opus 12 & above:

  • The examples below were made for older versions of Opus, where renames using regular expressions had to take care of file extensions themselves. This is why each example below has at least two commands, one for files (with extensions) and one for folders (without extensions).

    In Opus 12, things are easier. There is an Ignore Extensions checkbox in the Rename dialog, and corresponding IGNOREEXT argument for the Rename command, which tells Opus to preserve the extension automatically, and to only apply your regular expression to the main part of the filename.

    In general, this means you can take the regular expressions below which are for folders and use them for both folders and files. As well as halving the number of Rename commands, the regular expressions for folders are also less complex (since they don't have to worry about the file extensions).

    For example, if you had this for Opus 11 & below:

    @NoDeselect
    Rename REGEXP PATTERN="(Hello)(\..*)" TO="\1\2" TYPE=files
    Rename REGEXP PATTERN="(Hello)" TO="\1" TYPE=dirs
    

    You could simplify it to this for Opus 12 & above:

    @NoDeselect
    Rename IGNOREEXT REGEXP PATTERN="(Hello)" TO="\1"
    

    Also note, the regular expressions below are complex as they do a lot of things at once. You may find it easier to break things up into smaller parts, as shown in Script to perform multiple Regular Expressions

    Dots to spaces except in numbers is also similar to some of the examples below, but focuses on one particular task.

    The examples below assume strong familiarity with regular expressions. If you're new to regular expressions, try this thread instead: RegExp basics: Removing characters from start/end of names.

    --@Leo

Now back to the original post by David:


I haven't been active with the forum for quite some time,
but I think it may be a good time to post a few advanced RegExp renames I have here.
If you can better these, please let us know !
Leo knew of at least two of these a few years ago , via our private e-mails at that time.

Ellipsis refers to multiple '(' , '[' , '-' characters. [[[ ]]] , (( )) , etc.

  1. Rename dots to spaces, except in numbers , but keep ellipsis, ... , and collapse multiple spaces.

    @NoDeselect 
    Rename REGEXP PATTERN="(.*)((\.\.+)([^ .])|([^ .])(\.\.+)|  )(.*\..*)#" TO="\1\3\5 \4\6\7" type=files
    Rename REGEXP PATTERN="(.*)(([^.0-9 ])\.|\.([^.0-9 ])|  )(.*\..*)#" TO="\1\3 \4\5" type=files
    Rename REGEXP PATTERN="(.*)((\.\.+)([^ .])|([^ .])(\.\.+)|  )(.*)#" TO="\1\3\5 \4\6\7" type=dirs
    Rename REGEXP PATTERN="(.*)(([^.0-9 ])\.|\.([^.0-9 ])|  )(.*)#" TO="\1\3 \4\5" type=dirs
    

    Here are a few nonsense examples of this in action.

    Directory.Opus 99.0.7.3.The.world's.complete.file.management.solution.txt
    -> Directory Opus 99.0.7.3 The world's complete file management solution.txt

    Directory Opus...99.0.7.3 The world's...complete file management solution.txt
    -> Directory Opus ... 99.0.7.3 The world's ... complete file management solution.txt

    Directory Opus ...99.0.7.3 The world's... complete file management solution.txt
    -> Directory Opus ... 99.0.7.3 The world's ... complete file management solution.txt

    Directory Opus. ..99.0.7.3 The world's... complete file management solution.txt
    -> Directory Opus .. 99.0.7.3 The world's ... complete file management solution.txt

    Directory Opus 99.0...3 The world's complete file management solution.txt
    -> Directory Opus 99.0 ... 3 The world's complete file management solution.txt

  2. Add spaces around '-' characters, but keep ellipsis, --- , and collapse multiple spaces.

    @NoDeselect 
    Rename REGEXP PATTERN="(.*)(([^ -])(-)|(-)([^ -])|  )(.*\..*)#" TO="\1\3\5 \4\6\7" type=files
    Rename REGEXP PATTERN="(.*)(([^ -])(-)|(-)([^ -])|  )(.*)#" TO="\1\3\5 \4\6\7" type=dirs
    

    Here are a few nonsense examples of this in action.

    Directory-Opus-99.0.7.3-The-world's-complete-file-management-solution.txt
    -> Directory - Opus - 99.0.7.3 - The - world's - complete - file - management - solution.txt

    Directory Opus--99.0.7.3-The world's complete file management solution.txt
    -> Directory Opus -- 99.0.7.3 - The world's complete file management solution.txt

    Directory Opus-- 99.0.7.3 -The world's complete file management solution.txt
    -> Directory Opus -- 99.0.7.3 - The world's complete file management solution.txt

    Directory Opus- -99.0.7.3 ---The world's complete file management solution.txt
    -> Directory Opus - - 99.0.7.3 --- The world's complete file management solution.txt

  3. Add space to inside of '(' and ')' characters, but keep ellipsis, ((( or ))) , and collapse multiple spaces.

    @NoDeselect 
    Rename REGEXP PATTERN="(.*)(([^) ])(\))|(\()([^( ])|  )(.*\..*)#" TO="\1\3\5 \4\6\7" type=files
    Rename REGEXP PATTERN="(.*)(([^) ])(\))|(\()([^( ])|  )(.*)#" TO="\1\3\5 \4\6\7" type=dirs
    

    Here are a few nonsense examples of this in action.

    Directory Opus ((99.0.7.3) The world's complete file management solution).txt
    -> Directory Opus (( 99.0.7.3 ) The world's complete file management solution ).txt

    (Directory Opus 99.0.7.3 )x256)) )(The world's (best))complete (...) file management solution.txt
    -> ( Directory Opus 99.0.7.3 )x256 )) )( The world's ( best ))complete ( ... ) file management solution.txt

    Directory Opus 99.0.7.3 The world's ())) complete file management solution.txt
    -> Directory Opus 99.0.7.3 The world's ( ))) complete file management solution.txt

    Directory Opus ))99.0.7.3((The world's complete file management solution.txt
    -> Directory Opus ))99.0.7.3(( The world's complete file management solution.txt

  4. Add space to inside of '[' and ']' characters, but keep ellipsis, [[[ or ]]] , and collapse multiple spaces.

    @NoDeselect 
    Rename REGEXP PATTERN="(.*)(([^\] ])(\])|(\[)([^\[ ])|  )(.*\..*)#" TO="\1\3\5 \4\6\7" type=files
    Rename REGEXP PATTERN="(.*)(([^\] ])(\])|(\[)([^\[ ])|  )(.*)#" TO="\1\3\5 \4\6\7" type=dirs
    

    Here are a few nonsense examples of this in action.

    Directory Opus [[99.0.7.3] The world's complete file management solution].txt
    -> Directory Opus [[ 99.0.7.3 ] The world's complete file management solution ].txt

    [Directory Opus 99.0.7.3 ]x256]] ][The world's [best]]complete [...] file management solution.txt
    -> [ Directory Opus 99.0.7.3 ]x256 ]] ][ The world's [ best ]]complete [ ... ] file management solution.txt

    Directory Opus 99.0.7.3 The world's []]] complete file management solution.txt
    -> Directory Opus 99.0.7.3 The world's [ ]]] complete file management solution.txt

    Directory Opus ]]99.0.7.3[[The world's complete file management solution.txt
    -> Directory Opus ]]99.0.7.3[[ The world's complete file management solution.txt

And here's an example that is renamed under all of these one at a time.

  • GPSoftware--[[(((Directory Opus-99.0.7.3)x256 )(Jonathan.Potter, Leo.Davidson, Greg.Perry ))(The world's ...complete file management solution)].txt

Using 1) this becomes ...

  • GPSoftware--[[(((Directory Opus-99.0.7.3)x256 )(Jonathan Potter, Leo Davidson, Greg Perry ))(The world's ... complete file management solution)].txt

Then using 2) this becomes ...

  • [[(((Directory Opus - 99.0.7.3)x256 )(Jonathan Potter, Leo Davidson, Greg Perry ))(The world's ... complete file management solution)].txt

Then using 3) this becomes ...

  • GPSoftware -- [[((( Directory Opus - 99.0.7.3 )x256 )( Jonathan Potter, Leo Davidson, Greg Perry ))( The world's ... complete file management solution )].txt

Then using 4) this becomes ...

  • GPSoftware -- [[ ((( Directory Opus - 99.0.7.3 )x256 )( Jonathan Potter, Leo Davidson, Greg Perry ))( The world's ... complete file management solution ) ].txt

The ]'s are intentionally left unbalanced here just as example.

Regards,
Dave

I'm Dave in Green Bay , Wi ( or Michigan's UP )
USA


#6

(Dummy reply to fix a forum issue.)