I have some data stored in the variable “current_url”. To this I want to apply a regex function:
current_url.regex("/.com/(\w+)/")
How can I apply the regex and then store the result in another variable?
I have some data stored in the variable “current_url”. To this I want to apply a regex function:
current_url.regex("/.com/(\w+)/")
How can I apply the regex and then store the result in another variable?
Use executeScript_Sandbox
=> there you can run any Javascript code, including regular expressions. The result is stored in a variable.
Thanks for replying! I’m not familiar with JS though. Any idea how we can apply the regex to a given variable via JS?
Do we use like this?
${str}.match(/my_reg_ex/)
I have a macro that use regex in replace command, try to adapt it for your case.
Usually i do not use regex but this code (part of my macro) contains a regex applied in replace.
{
"Name": "Replace_Exact_Match_Multiple",
"CreationDate": "2020-8-26",
"Commands": [
{
"Command": "store",
"Target": "Roma",
"Value": "Variabile"
},
{
"Command": "executeScript_Sandbox",
"Target": "var mystring = ${Variabile}; var replaced = mystring.replace(/^Roma$/, \"RM\"); return replaced",
"Value": "Variabile"
},
{
"Command": "echo",
"Target": "${Variabile}",
"Value": ""
}
]
}