Sample Robotic Automation solution: City State ZIP regex - Splitting an array
This sample solution shows how to use a StringUtils component from the Advanced tab of the Toolbar to get the City, State, and ZIP from a single line of text by using Pega Robot Studio.
A StringUtils component is used to return an array of the City, State, and ZIP information, and then the automation breaks the array apart by using a StringArrayProxy object.
- Windows form: User Interface
- Automation: RegEx Example Stripping out an Address
The logic is triggered when you click thebutton on the Windows form.
The entry from the txtWholeAddress text box is sent to the StringUtils RegexReplace method where the regular expression (regex) syntax removes the commas and spaces in the input text string and separates the text with exclamation points (!). For example: Indiana, TX 56473 returns as Indiana!TX!56473. For more information on the syntax, see Special considerations.
The result of the RegexReplace method is then passed to a StringUtils Split method where the string is split into an array. The items are split based on the position of the exclamation points in the text string.
A proxy is created for the StringArray result. The Get method for the StringArrayProxy object is used to return the value of each array member beginning with member at index zero (0) – the first item.
The following image displays the regex syntax that is used with the RegexReplace method. Note that the input for the method contains text that is separated by a comma and spaces: City, ST ZIP. The ZIP code is optional. To represent this in Regex syntax, the commas and spaces in the text string are used to group the text.
Where "\w" represents words and "\s" represents spaces.
The replacement string removes any spaces or commas and inserts exclamation points before words 2 and 4. Therefore, the replacement syntax is:
You can download completed solutions for each version in the following table:
|Studio version||Built by using this build||Sample solution download|
|8.0||8.0.1037||Address Regex - Splitting 8.0|
|8.0 SP1||8.0.2037||Address Regex - Splitting 8.0 SP1|
|19.1||22.214.171.124||Address Regex - Splitting 19.1|