Replace DAC
The Replace dynamic advanced command is part of the variable commands. Use this command to replace specific text or text that matches a regular expression (regex) within a variable. A regex is a sequence of characters that defines a search pattern, useful for identifying specific text patterns within larger bodies of text. Drag it into a wizard from the Advanced commands view in the Nintex Wizard Editor to use it.
Before you begin:
Learn how to navigate the Nintex Wizard Editor of the Studio.
Understand how to create wizards and use advanced commands.
Understand variables.
Learn how to customize error handling within an advanced command.
Understand how to configure wizard fallbacks.
Use the Replace command to enhance your automation in various scenarios:
-
To clean up or standardize text entries in workflows, such as formatting data from forms or user inputs.
-
To replace specific words or phrases in text variables.
-
To replace special or specific characters.
-
Before using the Get array data command to perform calculations on numeric data. Non-numeric characters in array data will prevent calculations from working. By using this command, you can remove all non-numeric values to ensure the data is ready for processing.
-
To update data fields by using regular expressions to match complex patterns.
-
When there is a need to replace either the first, last, or all occurrences of matching text within a variable.
In the Nintex Wizard Editor, search for the Replace command and drag it into your steps. Use the table below to configure each field and understand the settings:
Field | Description | What to do |
---|---|---|
In the variable | The variable that contains the text you want to change. | Type the variable name or select it from the list. |
Replace the text | The text string you want to find and replace. |
Enter the specific source text:
|
Replace the text matching the regular expression | Option to use a regular expression to define the text you want to replace. | Select this option if you want to use a regular expression for matching the text. |
Test... | A button to open the regular expression tester. | Use the tester to ensure your regular expression is accurate before applying it in the workflow. |
Ignore letter case | Checkbox to ignore the case of the text while searching. | Select this checkbox if the match should ignore uppercase and lowercase differences. |
With | The text or regular expression to replace the matched string. |
Enter the replacement text:
|
Replace all/first/last | Options to replace all, only the first instance, or only the last instance of the matched text. | Select whether to replace all occurrences, the first occurrence, or the last occurrence of the match. |
The Regular expression tester allows you to test how regular expressions (regex) behave in two ways: finding text and replacing text. This is a powerful tool to verify your regex patterns before applying them in your wizard.
-
Find text: Use this to search for specific patterns in your source text and extract matches based on your regular expression. You can choose to return either a Full match or use Capture groups to organize matches.
-
Replace text: This allows you to replace text within the source based on either a regular expression or a specific string. It’s useful for cleaning up data, standardizing formats, or preparing text for further processing.
Use the table below to configure each field accurately and understand the settings:
Field | Description | What to do | ||
---|---|---|---|---|
Find text | Search Type | Option to choose between Full match (finds all matching text in the source) or Capture groups (returns grouped matches based on your regex pattern). | Select whether you want to match the entire expression or capture groups within the pattern. | |
Text to find | The regex pattern you want to use to search the source text. | Enter the regex pattern. For Capture groups, define named groups like this: (?<groupname>pattern). | ||
Full match | Delimiter | The character that separates each match found in the text. The default is a comma if left empty. | Enter the delimiter to separate each match. | |
Capture groups | Group delimiter | The character that separates each group result. The default is a pipe (|) if left empty. | Enter the delimiter to separate group results. | |
Match delimiter | The character that separates the individual matches within each group. The default is a comma if left empty. | Enter the delimiter to separate individual matches within a group. | ||
Regex options | Option to fine-tune the regex search behavior. The default is the Ignore case option. | Choose any relevant regex options (e.g., Ignore case) to control how the search works. For more details on these options, see the [Regex options section]. | ||
Replace text | Text to find | The exact text or regular expression you want to find in the source text. | Enter the specific text, characters, or regular expression pattern that you want to replace. | |
Replace with | The text you want to use to replace the matched pattern. | Enter the replacement text (e.g., a letter, number, text string, or characters including spaces) to update or change specific values. | ||
Ignore letter case | A checkbox to ignore case sensitivity when matching text. | Select this checkbox if you want to ignore case differences between uppercase and lowercase letters (e.g., "ABC" is a match for "abc"). | ||
Replace all/first/last | Options to specify whether to replace all, only the first instance, or only the last instance of the matched text. | Select whether to replace all occurrences, the first occurrence, or the last occurrence. | ||
Source text | The text where the search or replacement needs to occur. | Enter or paste the text you want to search through or change based on your regex or text pattern. | ||
Go > | Runs the search or replace operation using the defined regex pattern or text. Displays the search results or modified text in the Result field. | Click to run the regex-based search or the replacement operation, depending on your selection, and view the output in the Result field. | ||
Result | Displays the output after running the search or replace operation. | View the results of the search (matching text or capture groups) or confirm that the replacements occurred as expected. |
Additional resources for regular expressions
If you’re new to regular expressions or want to deepen your understanding, here are some useful resources:
-
For comprehensive information and tutorials on regular expressions, visit the Microsoft Developer Network (MSDN) Regular Expressions page. This resource provides in-depth explanations and examples on how to effectively use regex in different programming environments.
-
Use an online regex tester like Regex101. This website allows you to test your regular expressions in real-time and provides detailed explanations of each part of your regex pattern, making it easier to understand and debug.
Follow these best practices when using the Replace command:
-
Make sure the variable contains the correct data before making replacements.
-
Identify the text you want to replace, including any patterns or exact values.
-
Use the Find command first to locate specific text or patterns before using the Replace command.
-
If using regular expressions:
-
Test the expression using the Test... button to check for accuracy.
-
Ensure the regex does not unintentionally match other text.
-
Add extra Replace commands and fallbacks as needed.
-
-
Use the Ignore letter case option if the text you are replacing may appear in different cases (e.g., uppercase or lowercase).
-
Use the Note command to document the regular expression patterns and their purpose. This helps others who may use or update the wizard in the future.
This example shows how to use the Replace the text matching the regular expression option to standardize phone numbers by removing non-numeric characters like dashes, parentheses, and spaces.
-
Add the Note command to your wizard to document the regular expression pattern and its purpose.
-
Add the Set value command to define a variable with the source text.
-
Add the Replace command and complete the following fields:
-
In the variable: phoneNumbers
-
Select Replace the text matching the regular expression.
-
Enter [\D]. This regular expression matches any non-numeric character (e.g., dashes, parentheses, spaces).
-
Ignore letter case: This is not relevant for this example.
-
With: Enter a single space.
-
Select Replace all to ensure all non-numeric characters are removed.
-
-
Use the View variable list command to verify the command works as intended.
The following video provides guided instructions on how to use the Replace command:
When using regular expressions in the With field, you must select Replace the text matching the regular expression to make sure the system processes the regex correctly. If you select Replace the text, the system will treat the regex as regular text and won't perform the expected operation.
Regular expressions in the With field are useful for making dynamic changes, such as reformatting text, replacing patterns, or restructuring content.
In the following example image, a regular expression is used in the With field to reformat dates. The command changes dates from MM-DD-YYYY to YYYY/MM/DD by capturing and rearranging the parts of the date. This highlights how regular expressions can be used for flexible, pattern-based replacements.