Copy link to clipboard
Copied
Hi everyone,
I've tried googling but haven't found what I need; I just need a simple script that will remove the last 4 characters of the active layer name.
Because I use another script to import an image file and it retains the extention .png in the layer name and I just want to remove it, but without changing any other part of the layer name.
Thanks so much 🙂
3 Correct answers
app.activeDocument.activeLayer.name = app.activeDocument.activeLayer.name.replace(/\....$/, "");
If there is a chance that the filename extension may be 2, 3 or 4 (or even 1 or 5+) characters long, then a more robust/bullet-proof option would be:
.replace(/\.[^\.]+$/, '');
Still trying to wrap my head around regex. I still use this method for stripping off an extension:
.split('.')[0];
Explore related tutorials & articles
Copy link to clipboard
Copied
app.activeDocument.activeLayer.name = app.activeDocument.activeLayer.name.replace(/\....$/, "");
Copy link to clipboard
Copied
Works perfectly, thank you so much 🙂 I really appreciate your help 😄
Copy link to clipboard
Copied
If there is a chance that the filename extension may be 2, 3 or 4 (or even 1 or 5+) characters long, then a more robust/bullet-proof option would be:
.replace(/\.[^\.]+$/, '');
Copy link to clipboard
Copied
Still trying to wrap my head around regex. I still use this method for stripping off an extension:
.split('.')[0];

