Simple renaming - remove (eXX) from file name

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Simple renaming - remove (eXX) from file name

Postby mikado86 » Sun Mar 29, 2020 8:23 pm

Hello, im pretty new to Java, can anyone give me some pointers?

I have different files, example:
(e85)RandomName1.txt
(e86)RandomName2.txt

What i want is:

RandomName1.txt
RandomName2.txt

I know how to do this basic thing while using the match and replace, but i have to do this constantly, and with many more variables, so it gets tiresome, can anyone point me in the right direction to make a javascript with my current needs?

Thanks
mikado86
 
Posts: 5
Joined: Sun Mar 29, 2020 8:16 pm

Re: Simple renaming

Postby mikado86 » Sun Mar 29, 2020 8:27 pm

Oh yeah, forgot to mention, it *might* always have (e/RandomNumber/RandomNumber) at some point in the sentence, not necessarily at the beginning.
mikado86
 
Posts: 5
Joined: Sun Mar 29, 2020 8:16 pm

Re: Simple renaming

Postby Admin » Mon Mar 30, 2020 12:30 am

Hi, what is the criteria? Removing everything that is part of a name within ( ) and including () ? thanks
Admin
Site Admin
 
Posts: 1895
Joined: Tue Mar 08, 2005 8:39 pm

Re: Simple renaming

Postby mikado86 » Mon Mar 30, 2020 8:07 am

Admin wrote:Hi, what is the criteria? Removing everything that is part of a name within ( ) and including () ? thanks


That is somewhat correct, i want to remove everything that BEGINS with "(e" (letter "e" will remain constant, always), then has two random numbers (they will always be numbers, from 0 to 9), and ends with a ")", so it will delete 5 characters, it will not necessarily be at the start of a name, another example

RandomName1(e25)RandomName2.txt
to
RandomName1RandomName2.txt

i hope it was clear enough, thanks for the guidance
mikado86
 
Posts: 5
Joined: Sun Mar 29, 2020 8:16 pm

Re: Simple renaming

Postby therube » Mon Mar 30, 2020 12:25 pm

1:RegEx
Code: Select all
Match:  (.*?)(\(e\d\d\))(.*)
Replace:  \1\3

Match anything, non-greedy
up to, paren+e+#+#+paren, \(e\d\d\)
followed by anything else.

Keep any matching first part
ignore the second part
keep any matching third part.
therube
 
Posts: 921
Joined: Mon Jan 18, 2016 6:23 pm

Re: Simple renaming

Postby RegexNinja » Mon Mar 30, 2020 12:29 pm

Hi.. With (e85)RandomName1, what are the variables to keep/remove?
Case1: Remove: 1st-5chars
Case2: Remove 1st5hars when its like: (Any3Chars)
Case3: Remove 1st5hars when its like: (eAny2Digits)
Case4: Remove 1st5hars when its like: (1LowerCaseAny2Digits)
Case5: Specify: RandomNameFormat (and lose everything else)


Here's a regex-replace to handle the Case4 condition, it seems the most likely case.
I'm just learning javascipt myself, so I dunno if its the best way, lol

newName=name.replace(/\([a-z]\d{2}\)(.*)/, '$1')
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Simple renaming

Postby RegexNinja » Mon Mar 30, 2020 12:33 pm

Woops! Nobody had replied when I started typing the post, lol..
This only matches the Case3 condition:

newName=name.replace(/\(e\d{2}\)(.*)/, '$1')
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Simple renaming

Postby RegexNinja » Mon Mar 30, 2020 12:55 pm

Sorry. Just noticed you want to remove ALL occurrences of: (eAny2Digits)

newName=name.replace(/\(e\d{2}\)/g, '')
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Simple renaming

Postby therube » Mon Mar 30, 2020 1:03 pm

(Oops on my end too. Didn't realize we were in JavaScript renaming.)
therube
 
Posts: 921
Joined: Mon Jan 18, 2016 6:23 pm

Re: Simple renaming

Postby mikado86 » Mon Mar 30, 2020 8:04 pm

RegexNinja wrote:Sorry. Just noticed you want to remove ALL occurrences of: (eAny2Digits)


Yes, thats what i want to do, normally, there will only be "one" case of "(eAny2Digits)" at most per file, but thats the gist of it.

therube wrote:(Oops on my end too. Didn't realize we were in JavaScript renaming.)


Yeah that is correct, i have a general idea of how to do it with a regular match/replace input, but as i said i have to do this constantly and with more values than "(eXX)", as far i am aware, i can only save/load one single match replace values, -- so i want to make a javascript to automate the process somewhat, thanks!
mikado86
 
Posts: 5
Joined: Sun Mar 29, 2020 8:16 pm

Re: Simple renaming

Postby mikado86 » Mon Mar 30, 2020 8:21 pm

RegexNinja wrote:Sorry. Just noticed you want to remove ALL occurrences of: (eAny2Digits)

newName=name.replace(/\(e\d{2}\)/g, '')



This solved my question btw, thanks a lot!, now i just need to learn to make a sequence but i should be able to figure that myself
mikado86
 
Posts: 5
Joined: Sun Mar 29, 2020 8:16 pm


Return to Javascript Renaming