Locating a string and copying it to the beginning of a dir

A swapping-ground for Regular Expression syntax

Locating a string and copying it to the beginning of a dir

Postby cosmicmonolith » Mon Nov 21, 2022 6:49 pm

I have a bunch of directories like this

Some_random_text-SHA056-other_text-end
meaningless_words__strung_together-(SHA105)-More_words-WORD
Another_Folder_With_Files_In_It-SHA006-2011-FOLDER


The common factor is they all have SHA[0-9][0-9][0-9] in them somewhere.

Is it possible to use regex to locate the string beginning with SHA, and copy the following three digits to the start of the directory (and then use add/replace to enclose in brackets)? The end result would look like this:

[056] Some_random_text-SHA056-other_text-end
[105] meaningless_words__strung_together-(SHA105)-More_words-WORD
[006] Another_Folder_With_Files_In_It-SHA006-2011-FOLDER
cosmicmonolith
 
Posts: 2
Joined: Mon Nov 21, 2022 6:43 pm

Re: Locating a string and copying it to the beginning of a dir

Postby cosmicmonolith » Mon Nov 21, 2022 7:23 pm

i think i got it

Code: Select all
MATCH: ^(.*\w[SHA])(\d{3})(.*)$
REPLACE: [\2] \1\2\3
cosmicmonolith
 
Posts: 2
Joined: Mon Nov 21, 2022 6:43 pm


Return to Regular Expressions