Replace

This activity is used to replace a character within a specified string by applying the regex
pattern given.

Technical Reference

 

 

 

INPUT

InputString: Enter the input string to which the Regex pattern has to be applied.

Pattern: Enter the Regex pattern to be used.

RegexOption: Choose from the drop-down menu.

Replacement: Enter the replacement text to be used in the input string

 

 

 

 

 

MISC

Display Name: Displays the name of the activity. You can also customize the activity name to help troubleshoot issues faster. This name will be used for logging purposes.

SkipOnError: It specifies whether to continue executing the workflow even if it throws an error. This supports only Boolean value “True or False”

True: Continues to execute the workflow irrespective of any error thrown.

False: Stops the workflow if it throws any error

Version: It specifies the version of the Regex Automation feature in use.

OUTPUT

Text: Declare a variable here to view the result of the replaced string. This is not a mandatory field however declare a variable to get the result.

* Mandatory fields to execute the workflow.

Use Case

The following activity illustrates how we can use the replace activity from the
Regex feature to replace specified values retrieved by applying the regex pattern
to the input string with the given replacement value. Here we are going to use the
regex pattern for Email ID and replace both the email ID's in the input string to Test.

Steps to execute the bot

1.     Drag and drop the replace activity.

2.     Click on the activity.

3.     Enter the variable given in the variable type for the input string. Here it is “Text”.
 


 

4.     Enter the Regex pattern to be applied to the string. Since we are going to replace the
Email ID, the pattern is "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}
~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\
x0c\x0e-\x7f])*"")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|
\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|
[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\
x0c\x0e-\x7f])+)\])"

5.      Choose the Regex option from the Drop-Down.

6.      Enter the replacement value which has to be used in place of the regex applied.
 Here it is” Test”.

7.      Declare a variable in the text box of the output segment. Here it is “Result”.

8.      Drag and drop a writelog activity below the replace activity.

9.      Click on the writelog.

10.   In the input string, enter Result.ToString

11.   Enter the log level as “Info”.

12.   Execute the activity.

The given regex pattern retrieves the email id from the input string. Since we have
given that pattern and entered the replacement value as “Test”, the bot replaces
the Email ID in the given string with the word “Test”.