替换文本

动词:replaceText

使用新内容替换在文本中找到的术语、片段或正则表达式的所有出现项。

语法

replaceText --texttoparse(String) [--useregex(Boolean)] --pattern(String) [--regexOptions(DisplayableRegexOptions)] --textpattern(String) [--replacement(String)] (String)=value

输入

脚本 设计器 必需的 AcceptedTypes Description
--texttoparse 要解析的文本 必需的 文本 要替换其中出现项的文本。
--useregex 使用正则表达式 可选 BOOLEAN 启用后,将使用正则表达式在要解析的文本中执行搜索。
--pattern 正则表达式 仅当“使用正则表达式”为 True 时 文本 用于查找要替换的文本摘录的正则表达式。
--regexOptions 正则表达式选项 可选 可显示的正则表达式选项 帮助执行正则表达式搜索的过滤选项:
  • 已编译
  • 区域设置不变量
  • ECMA 脚本
  • 显式捕获
  • 忽略大小写
  • 忽略模式空格
  • 多行
  • 从右到左
  • 单行

  • 此参数中接受多个过滤选项。
    --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
    

    另请参阅

  • 向正则表达式添加转义字符
  • 向文本添加转义字符
  • 计算散列
  • 更改文本大小写
  • 检查文件
  • 并置文本
  • 将 HTML 转换为文本
  • 计算在文本中的出现次数
  • 文本字符计数
  • 创建随机文本
  • 通过正则表达式创建表
  • 空文本变量或 Null 文本变量
  • 通过正则表达式查找
  • 在文本中查找出现项
  • 设置文本格式
  • 获取子文本
  • 通过正则表达式获取文本
  • HTML 转换为 Markdown
  • 向文本插入新行
  • 连接文本
  • 填充文本
  • 解析 URI
  • 除去变音符号
  • 除去转义字符
  • 替换部分文本
  • 拆分文本
  • 修剪文本空白