替换文本
动词:replaceText
使用新内容替换在文本中找到的术语、片段或正则表达式的所有出现项。
语法
replaceText --texttoparse(String) [--useregex(Boolean)] --pattern(String) [--regexOptions(DisplayableRegexOptions)] --textpattern(String) [--replacement(String)] (String)=value
输入
| 脚本 | 设计器 | 必需的 | AcceptedTypes | Description |
|---|---|---|---|---|
| --texttoparse | 要解析的文本 | 必需的 | 文本 | 要替换其中出现项的文本。 |
| --useregex | 使用正则表达式 | 可选 | BOOLEAN | 启用后,将使用正则表达式在要解析的文本中执行搜索。 |
| --pattern | 正则表达式 | 仅当“使用正则表达式”为 True 时 | 文本 | 用于查找要替换的文本摘录的正则表达式。 |
| --regexOptions | 正则表达式选项 | 可选 | 可显示的正则表达式选项 | 帮助执行正则表达式搜索的过滤选项:此参数中接受多个过滤选项。 |
| --textpattern | 要查找的文本 | 仅当“使用正则表达式”为 False 时 | 文本 | 应在要解析的文本中查找并替换的术语或片段。 |
| --replacement | 替换为 | 可选 | 文本 | 应替换在要解析的文本中找到的所有出现项的新术语或短语。 |
| --texttofind | 要查找的文本(已废弃) | 可选 | 文本 | 应在要解析的文本上查找以进行替换的文本。此参数已废弃,请改为使用要查找的文本参数。 |
| --ignorecase | 忽略大小写(已废弃) | 可选 | BOOLEAN | 启用后,将指定不区分大小写的匹配。此参数已废弃。 要选择正则表达式选项,请改为使用正则表达式选项。 |
| --activateescapesequences | 使用转义序列(已废弃) | 可选 | BOOLEAN | 启用后,将允许使用特殊转义字符。此参数已废弃。 要选择正则表达式选项,请改为使用正则表达式选项。 |
输出
| 脚本 | 设计器 | AcceptedTypes | Description |
|---|---|---|---|
| 值 | 更改后的文本 | 文本 | 所有替换项均替换为新内容的文本。 |
示例
示例 1:使用替换文本命令在文本的所有实例中将术语“wgd”替换为“IBM”。
defVar --name textToReplace --type String --value "wgd Automation"
defVar --name textToFind --type String --value wgd
defVar --name newText --type String --value IBM
defVar --name changedText --type String
// Replaces the term "wgd" within the text "wgd Automation" with "IBM".
replaceText --texttoparse "${textToReplace}" --textpattern "${textToFind}" --replacement "${newText}" changedText=value
logMessage --message "${changedText}" --type "Info"
// This example produces the following output: IBM Robotic Process Automation.
示例 2: 对于 "15055-480" ,使用 替换文本 命令通过正则表达式 "\d\d\d\d\d\d-\d\d\d" 替换所有出现的文本。
defVar --name textToReplace --type String --value "IBM Robotic Process Automation - Rio Preto: 04730-090"
defVar --name newContent --type String --value "15055-480"
defVar --name regularExpression --type String
defVar --name changedText --type String
setVar --name "${regularExpression}" --value "\\d\\d\\d\\d\\d-\\d\\d\\d"
logMessage --message "Text before replacement: ${textToReplace}" --type "Info"
// Replace all occurrences of the regular expression "\\d\\d\\d\\d\\d-\\d\\d\\d" by "15055-480".
replaceText --texttoparse "${textToReplace}" --useregex --pattern "${regularExpression}" --regexOptions "RightToLeft" --replacement "${newContent}" changedText=value
logMessage --message "Text after replacement: ${changedText}" --type "Info"
// This example produces the following result:
// Text before replacement: IBM Robotic Process Automation - Rio Preto: 04730-090
// Text after replacement: IBM Robotic Process Automation - Rio Preto: 15055-480