Question

5
Replies
8512
Views
Bryan Chen (BryanC97)
Infosys Limited

Infosys Limited
US
BryanC97 Member since 2017 4 posts
Infosys Limited
Posted: February 13, 2018
Last activity: March 1, 2018
Posted: 13 Feb 2018 11:01 EST
Last activity: 1 Mar 2018 10:32 EST
Closed
Solved

Regular Expression to extract a substring?

Here's the problem:

You have an arbitrary length string (it could be a 2000 character string or more) that you have to extract a substring from. The easiest way I know is using RegEx. The hardest way I know is using an activity with when/loops.

I'm not too particularly fond of creating a whole new activity with different when/loops when I have to look for a completely different substring, or when I'm looking for the same substring in a completely different formatted string.

The only out-of-the-box RegEx I can find in 7.1.x is from String (Pega-RulesEngine) in expression builder, however they don't extract substrings with RegEx.

so I'm left with using a Java step with the code below.

String mydata = tools.getParamValue("Input");
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(tools.getParamValue("Regex"));
java.util.regex.Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
      tools.putParamValue("Output" ,PropertyInfo.TYPE_TEXT, matcher.group(0));
}

So basically you just put this java step in an activity, and have the string parameters: Input, Regex, Output.

You do property set on Input and Regex, and extract a string to Output by running the activity.

Any features like this in Pega without using Java steps?

On a side-note: The projects I'm working is migrating to 7.3.1 soon.

Low-Code App Development Data Integration Java and Activities
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.