This content has been archived and is no longer being maintained.

Table of Contents

Article

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.

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 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
7.1 7.1.26 Address Regex - Splitting 7.1
8.0 8.0.1037 Address Regex - Splitting 8.0

Published July 14, 2017 — Updated October 30, 2017


0% found this useful

Have a question? Get answers now.

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