If you use the above string replacement code in RPA for Firefox you get:
[error] Line 2: E501: [Firefox only] executeScript_Sandbox does not support regular expressions.
Here is my solution for it. Instead of regex I use for {..} loop to do the character replacement. This “non regex” version runs in both, Chrome and Firefox.
{
"Name": "replace string",
"CreationDate": "2024-6-6",
"Commands": [
{
"Command": "store",
"Target": "123&,45 ; :xx67:89",
"Value": "s",
"Description": "Task: Remove all non numeric characters from this string"
},
{
"Command": "echo",
"Target": "String=${s}",
"Value": "blue",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var inputString=${s};\nvar numericString = '';\nfor (var i = 0; i < inputString.length; i++) {\n var char = inputString.charAt(i);\n if (char >= '0' && char <= '9') {\n numericString += char;\n }\n}\nreturn numericString;",
"Value": "n",
"Description": "E501 workaround: Replace chars without using regular expression, so it works in Firefox, too"
},
{
"Command": "echo",
"Target": "Number=${n}",
"Value": "green",
"Description": "Clean string"
}
]
}