Yes.
Also, please look into the bug when certain brackets are in the folder name.
function insertAfterText(inputString, searchText, insertText) {
// Find the index of the searchText
const index = inputString.indexOf(searchText);
// If searchText is found (index is not -1)
if (index !== -1) {
// Insert the insertText after the searchText
return inputString.slice(0, index + searchText.length) + insertText + inputString.slice(index + searchText.length);
}
// Return the original string if searchText is not found
return inputString;
}
originalString = name;
searchFor = object("container");
textToInsert = " - ";
newName = insertAfterText(originalString, searchFor, textToInsert);
TheGhost78 wrote:If the parent folder contains [, ( or ) then it comes up with a syntax error using the three formulas below. It doesn't happen with ], { or } in the folder name.
name.search(object('container')) == -1
name.toLowerCase().search(object('container').toLowerCase()) == -1
!name.match(object('folder').replace(/.*\\(.+)\\$/,'$1'))
This formula works fine:
!name.startsWith(object('folder').replace(/.*\\(.+)\\$/,'$1'))
function escapeRegExp(text) {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
name.search(escapeRegExp(object('container'))) == -1
name.search(object('container').replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) == -1