
Given a situation where a character can have an associated config file for a script: Character name: Brad the Hirsute Config Handout name: IAConfig-Brad the Hirsute ...I have a script that listens for a character name change so that it can prompt if there is a config file to rename, too. So if Brad the Hirsute becomes Brad the Bald and he had a config file out there under his old name, the player should get a prompt asking if they want to rename the config. The problem is, I'm getting no hits on my regex test... const handleCharNameChange = (character, prev) => {
let oldrx = new RegExp(`/(iaconfig-)(${prev.name})/`, 'gi');
// group 1: iaconfig- from iaconfig-prevName
// group 2: prevName from iaconfig-prevName
let newrx = new RegExp(`/(iaconfig-)(${character.get('name')})/`, 'gi');
// group 1: iaconfig- from iaconfig-characterame
// group 2: charactername from iaconfig-charactername
let testhos = findObjs({ type: "handout" }).filter((h) => { return oldrx.test(h.get('name')) });
log(`There are ${testhos.length} handouts satisfying the first naming test.`);
// returns 0
testhos = findObjs({ type: "handout" }).filter((h) => { return oldrx.test(h.get('name').toLowerCase()) });
log(`There are ${testhos.length} handouts satisfying the second naming test.`);
// returns 0 The text of the name is in there, as this formation works: let testhos = findObjs({ type: "handout" })
.filter((h) => { return h.get('name').toLowerCase() === `iaconfig-${ prev.name.toLowerCase() }` })
.map((h,i) => { log(`(${i}): ${h.get('name')}`) });
// outputs "(1): IAConfig-Brad the Hirsute"
I have tried dropping the name to lower case when the regex is made (shouldn't make a difference... and it didn't). I tried including a non-capturing group with an or condition of either a hyphen or the html entity for a hyphen. I tried using the decodeUrlEncoding() function from the Utility Functions in the API reference (even though that was listed to be for the notes and GM notes fields). None of that seems to work. I can't think it's something about encoding in the field since the explicit name test works (flattening everything to lower case and skipping the regex completely), so what am I doing wrong in the regex?