Table of Contents

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.

Project items

  • Windows form: User Interface
  • Automation: RegEx Example Stripping out an Address

Automation details

The logic is triggered when you click the Break Apart into Three button 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.

Special considerations

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.

An example of the Regex syntax

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:$1!$2!$4

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 19.1.2.0 Address Regex - Splitting 19.1
Suggest Edit

33% found this useful

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.