Je suis en train de créer un script pour remplacer les noms de colonnes en fonction d'une correspondance d'expression régulière. Je parcours toutes les colonnes et l'expression régulière correspond à une nouvelle chaîne. Fonctionne bien et pratique pour raccourcir les noms de colonnes - sauf lorsque je remplace par une chaîne qui commence par un nombre - c'est parce que la référence arrière est gâchée (\1 devient \133 dans le cas ci-dessous)
En python, il existe une « référence arrière sans ambiguïté » pour contourner ce problème. Y a-t-il la même chose en JSL ? J'ai lu quelque part qu'il utilise peut-être des références arrière de type Perl, mais je n'ai pas trouvé où cela est documenté.
Merci,
Pêche
colName = "COLUMNNAMETEST LONGNAMESHORTEN33339E0HS KEEPTHIS";
Rename_regx = "LONGNAMESHORTEN2339E0HS111";
Rename_to = "39E0H";
newname=Regex( colName,
"(.*?)(" || Rename_regx || ")(.*)", // match
"\1" || Rename_to || "\3") // replace match with
// "\g<1>" || Rename_to || "\g<3>") // python like unambiguous doesn't owrk
colName = "COLUMNNAMETEST LONG\1NAMESHORTEN2339E0HS111 KEEPTHIS";
Rename_regx = substitute("LONG\1NAMESHORTEN2339E0HS111","\","\\");
Rename_to = "39E \1 0H";
// \Q starts a sequence that ignores escapes
newname=Regex( colName,
"(.*?)(" || Rename_regx || ")(.*)", // match
"\1\Q" || Rename_to || "\E\3"); // replace match with
show(newname); // newname = "COLUMNNAMETEST 39E \1 0H KEEPTHIS";
// notice:
// \Q begins "quoting" and \E ends it
// the \Q has a side effect of ending the \1 (which is what you asked)
// the \1 in the replacement is NOT expanded inside the \Q...\E
// at the very top, it takes care of escaping any escapes with substitute,
// which *could* be an issue
// what else? upper and lower case:
// \L begin lower casing
// \U begin upper casing
// \E ends *all* \L, \U, or \Q
show(regex("aBcDEf","(..)(..)(..)","\1\L \2 \U\3"));//"aB cd EF"
// \l (lower case L) lower case the next character
// \u upper case the next character
show(regex("ABcdEF","(..)(..)(..)","\1 \u\2 \l\3"));//"AB Cd eF"
// the Q, L, and U modes share a common E (end)
// the q and l are not persistent and only apply to the next character.
// upper/lower is probably very ASCII specific, no Unicode magic.
// this is poorly documented here: https://www.jmp.com/support/help/en/17.2/index.shtml#page/jmp/escaped-characters-in-regular-expressions.shtml
// somehow all the escapes have been lumped together in the worst possible way.
Edit : la fonction regex() comporte deux paramètres qui utilisent des échappements. Le paramètre 2 est le modèle et utilise les échappements comme prévu, et les \Q \U \L \E \u \l n'y ont pas leur place. Le paramètre 3 est le remplacement, et les \Q \U \L \E \u \l peuvent y être utilisés. Les références arrières \1 \2 \3 ... peuvent être utilisées dans parm2 et parm3.
Modification du 14 août 2025 : en fait, \U\u\L\l peut être utilisé dans le paramètre 2 et correspondre à un seul caractère : u majuscule, U non majuscule, l minuscule et L non minuscule. De plus, \A et \Z correspondent aux positions de début et de fin.