I have a large number of strings I need to perform some replace operations. I have created an array called ARR from a variable called Replacements where I have the substitutions I need, in the following way
Code: Select all
Replacements = ;This the variable
(
retire:quite
entrada:admisión
arnés:mazo de cables
muelle:resorte
)
arr := {} ; I create an array named Arr with the contents of Replacements!!!
for x,y in strsplit(Replacements,"`n", "`r"
arr[strsplit(y, ":").1] := strsplit(y, ":").2
Code: Select all
For Word1,Word2 in arr
TargetText:=StrReplace(SourceText,Word1,Word2)
So far so good.
The thing is, I need two extra things for this to be useful. First, I need to maintain capitalization because I might have the entry "retire" but it could also be "Retire", with a capital R. Or it could be "RETIRE", all in uppercase (there are only those two types of capitalization). And of course, it's not optimal having to write all capitalization possibilities!
This, I have it covered thanks to the function JEE_StrReplaceMaintainCase I could find in this same forum. It works beautifully as can be seen in the following link. replace text maintain case
But alas, I have another problem. I need to use Regular Expressions and the function JEE_StrReplaceMaintainCase only works with StrReplace. I have not been able to adapt it to use RegexReplace.
The thing, I would also need things like
Code: Select all
Replacements =
(
hacia a(dentro|fuera):hacia $1
njunto de (\w+)s\b:njunto de $1
nto(s?) de arneses:nto$1 de mazo de cables
)
So how the heck do you think you can replace a NeedleRegEx within a Haystack so capitalization is preserved? So I can apply it to my large array of a hundred substitutions (or more)?
The thing should be that, if I have
Code: Select all
Replacements=
cas(on)?a(s?):choza$2
Any ideas? Only two possibilities, either the replaced string has to go all in uppercase, or only the first case. Nothing crazy like CamelCase.