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?
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)
Quick Answer if the pre text is constant use a Mid statement then this will take out the issue the other guy had with the right. i.e.
Mid("Please take note of your order reference: 525",42,6)
If you aim for a maximum number length it will stop at the end anyway.
A few things here:
-Your pattern isn't matching because it's looking for a constant string of letters from start to finish (^
anchors to the beginning of the string and $
anchors to the end).
-You're replacing the pattern with a space, not an empty string, so you'll end up with a bunch of spaces in your result even if you correct the pattern.
-You said you only want to replace alphabetic characters, but it looks like you also want to get rid of spaces and colons.
Try replacing [A-Za-z :]+
with "".
Your goal is to retrieve number from string then use Right()
:
Right("Please take note of your order reference: 525", 3)
This will return only numeric.
Regards
Vimal