使用替换
action 从源字符串中查找文本片段,并将其替换为另一段文本。
A regular expression is a sequence of characters
that define a search pattern. For example, to find all email addresses in the source
string, specify the following as a regular expression:
\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
.
注:
- 使用输入变量时,替换
action 可能无法替换字符串中的回车和换行符 (CRLF) 字符。 相反,您可以使用换行符变量来替换 CRLF 字符。 换行符变量返回与系统相关的行分隔符字符串。 请参阅 预定义的变量 以了解换行符变量的功能。
- 当您在正则表达式模式中使用 $ 字符时,正则表达式字段可能会显示错误,因为 $ 被视为变量规范的开始。 因此,我们建议您改用 $。
过程
要替换指定字符串中的文本,请执行以下操作:
-
在
Actions
面板中,从字符串
package 双击或拖动替换
action。
-
在源字符串字段中,指定源字符串。
-
在查找字符串字段中,指定子字符串。
-
In the When finding field, select one of the
options:
-
Match case: Matches the case of the text.
-
Do not match case: Does not match the case of the
text.
-
In the The "find string" is field, select one of the
options:
-
A regular expression: The substring is a regular
expression
-
Not a regular expression: The substring is not a
regular expression.
- 可选:
在开始位置字段中,指定开始位置。
操作将从您在此字段中指定的值开始。 例如,如果您在源字符串 “Big blue ocean” 的开始于字段中指定 5,当机器人运行时,该操作会忽略前面的四个字符(“Big”,包括空格字符),并在 “blue ocean” 中搜索子字符串。
- 可选:
在计数字段中,指定必须替换已找到的字符串的次数。
例如,在源字符串“Big blue ocean, blue fish, blue sky”中,您希望将前两个“blue”实例替换为“green”。 在计数字段中输入 2,在开始自字段中输入 5,在替换为字段中输入 green。 bot 运行时,产生输出为 action
green ocean, green fish, blue sky。
注: 默认情况下,计数字段中的值设置为 -1,这意味着将替换找到的字符串的所有实例。
-
在替换为字段中,指定要替换字符串的文本。
-
在将输出分配给变量列表中,指定将保存新字符串的变量。
-
单击保存。