Extend Make Web-safe rename preset?

Hello, I use the Make Web-safe rename preset from time to time. I would like to know if this could be changed not to allow double underscores (or triple), periods, and any special character (e.g. [, (, #) to exist. Of course, I would like to save it as a preset like MyWebsafe. Thanks for any help.

(.*)([^-0-9a-zA-Z._]+)(.*)#

Special characters already get removed, I'd say.

What should happen to two or more underscores? Remove completely? Reduce to a single underscore?

Maybe you can share some test strings?

Hi thanks for the reply. I want it reduced to single underscore. This is what I would want.

Wheel Loaders, Heavy____Transports, HeavyMachinery____Movie.webm

converted to

Wheel_Loaders_Heavy_Transports_HeavyMachinery_Movie.webm

Thanks

A bit too much for a single regex, you'll need a rename script.

// https://resource.dopus.com/t/extend-make-web-safe-rename-preset/43996

function OnGetNewName(getNewNameData) {
    if (getNewNameData.item.is_dir) return;

    var tmpStem = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    tmpStem = tmpStem.replace(/ /g, '_');

    tmpStem = tmpStem.replace(/[^-0-9a-zA-Z._]+/g, '_');

    tmpStem = tmpStem.replace(/_+/g, '_');

    return tmpStem + tmpExt;
}

Save 43996.orp to

%appdata%\GPSoftware\Directory Opus\Rename Presets
2 Likes

I found a little time to play with Reg Expressions this morning.
It has been a while, but when I learned them I think Directory Opus was using a very early regular expression library which inadvertently helped me.

Try this.

 Rename IGNOREEXT REGEXP PATTERN="(.*)(([^-0-9a-zA-Z._]+)|(__)|(\.))(.*)#" TO="\1_\6" ```
1 Like

This super, also to super to understand a script function can be used in this area. Thanks so much!

That works great, I like the idea of having it in button! Thanks so much!