Blueprism: how to use the replace function in a calculation stage?

AntsaR picture AntsaR · Nov 16, 2017 · Viewed 10.4k times · Source

I am reading a text from an application using BluePrism. The text has the following structure (the number varies from case to case): "Please take note of your order reference: 525". I need to be able to extract the number from the text. Looking at the calculation stage, there is a replace function: replace(text, pattern, new-text). I want to use this function to replace all alphabetic characters in my text with an empty string to return only whatever is numeric. How can I input that in the pattern? So I want something like this:

Replace([Order confirmation text ], /^[A-z]+$/, " ")

Also, I tried to look for a proper documentation for the VBOs that are shipped with blueprism, but couldn't find any. Does anyone know where we can get documentations for blueprism functions?

Answer

Andrzej Kaczor picture Andrzej Kaczor · Nov 17, 2017

The Replace() function in calculate stage is the simplest possible one. It's not a regex one!

So, if the stirng is always in that format, then you can use:

Replace([Text],"Please take note of your order reference:","")

If the text is not always that standard, then you should rather use a regular expressions. To do that, you need to use an object, that will invoke a regex code.

In the standard blueprism objects, you can find:

Object: Utility - Strings C#
Action: Extract Regex Values

I think there is no Regex Replace action, by default, so if you'd like to, then you have to implement it. Below you can find a code that I am using:

Dim R as New Regex(Regex_Pattern, RegexOptions.SingleLine)
Dim M as Match = R.Match(Text)
replacement_result = R.Replace(Text,Regex_Pattern,replacement_string)

Parameters