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

11,892

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

Share:
11,892

Related videos on Youtube

AntsaR
Author by

AntsaR

Updated on June 04, 2022

Comments

  • AntsaR
    AntsaR almost 2 years

    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?

    • AntsaR
      AntsaR over 6 years
      I have also tried using the Utility-Strings VBO, using the Extract Regex action with a regex \d+, but I don't get anything in my output collection.
  • AntsaR
    AntsaR over 6 years
    You are right, I was adding white space instead of replacing with empty string, and yes, I only want the numbers. so right now, i have something like this: Replace([Order confirmation text ], [A-Za-z :]+, ""), and when I evaluate the expression, I get the error: Missing data: [A-Za-z :]+. So I am thinking maybe the pattern here needs to be an actual string instead of a regex.
  • CAustin
    CAustin over 6 years
    You still need to put the forward slashes around it
  • AntsaR
    AntsaR over 6 years
    Yeah, even with the forward slashes I get the same error. I think the pattern argument here expects a string input.
  • AntsaR
    AntsaR over 6 years
    Yep, this is also what I ended up doing. I just specified the exact text as the "pattern", and will have to use the strings utility for better solutions. thanks!
  • Celso Lívero
    Celso Lívero about 6 years
    the number varies from case to case in other words if the number is 54 or 54321 your answer is incorrect
  • carusyte
    carusyte about 5 years
    But the "Extract Regex Values" action only extracts the matched strings instead of replacing that matched string with targeted value. How to accomplish the replacement utilizing regex is still a question.
  • Andrzej Kaczor
    Andrzej Kaczor about 5 years
    Hey, I've added regex relace code to my answer. Enjoy!
  • Leni
    Leni almost 5 years
    @AndrzejKaczor Thanks I found this quite useful. But R.Replace(Text,Regex_Pattern,replacement_string) gives compiler warning. (Access of shared member, constant member, enum member or nested type through an instance) Better user Regex.Replace(Text,Regex_Pattern,replacement_string)