Sample 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® Robotic Automation Studio versions 7.1 and 8.0.
A StringUtils component is used to return an array of the City, State, and ZIP information, 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 the
button on the Windows form.
The entry from the txtWholeAddress text box is sent to the StringUtils RegexReplace method where the 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:
Published July 14, 2017 — Updated October 30, 2017