Blueprism: how to use the replace function in a calculation stage?
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)
Related videos on Youtube
AntsaR
Updated on June 04, 2022Comments
-
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 over 6 yearsI 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 over 6 yearsYou 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 over 6 yearsYou still need to put the forward slashes around it
-
AntsaR over 6 yearsYeah, even with the forward slashes I get the same error. I think the pattern argument here expects a string input.
-
AntsaR over 6 yearsYep, 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 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 about 5 yearsBut 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 about 5 yearsHey, I've added regex relace code to my answer. Enjoy!
-
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)