cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of extract regex Values

VratHimbo
Level 6

Hi guys,
i've some problems with using the "extract regex values".
I need to extract only number inside my string values.
EX. --> 998,145lb $ i need to extract 998145.

I've found this pattern "\d+(\.\d{1,2})?" and i have 2 matches 998 and 145.
Is this pattern correct? I've tried with the test regex and the match is True but when i try to configure the extract regex values the collection is empty.
15478.png
So, my goal is to extract this text from a collection field (inside a loop) and then re-insert the correct data inside my collection, which is the best method to do that?

Thanks in advance



------------------------------
Vrat Himbo
------------------------------
9 REPLIES 9

ewilson
Staff
Staff
Hi @VratHimbo,

There are lots of different ways to match just numbers. The most basic is is simply \d+. However, this will match each individual digit. Since you want to match complete numbers you can apply grouping as this (\d+). This will match only digits and will keep them in groups, so instead of getting 9 9 8 1 4 5 it will group them as 998 and 145.

Cheers,


------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

Thanks @ewilson,
how can I configure the collection in input and output to have the single value 998145?

I haven't found bp documentation about this object.

Thanks, ​​

------------------------------
Vrat Himbo
------------------------------

Which VBO are you using for your regex work?

Cheers,

------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

I need to use the one in utility string in blue prism.

Thanks,

------------------------------
Vrat Himbo
------------------------------

Ah, I think I understand what's going on now. The Extract Regex Values action assumes you will pass in a regular expression that uses Named Groups. This is a bit limiting in my opinion because it's basically assuming your input data will always be the same consistent format. In your particular case, this may apply if you're only dealing with prices like in your example. However, if the input data could vary in any way you need more flexibility.

To answer your specific example, you'd want go with a regex like this (?<Group1>\d+)\D(?<Group2>\d+). Then you would want to populate two rows in the Named Values collection and set the Name of each row to Group1 and Group2 respectively. When you run it, the response collection will look like this:

15456.png
After that, it's just a matter of cycling through that collection and concatenating the values together into your new collection.

Cheers,



------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

Thanks @ewilson,
last question, in your opinion is a good approach to loop inside the collection and use the "replace" function if i have a fixed value?
For example: 998.145 $ Replace(Trim("collection.Invoice","$",""))​
and the same for the comma?
Thanks in advance

------------------------------
Vrat Himbo
------------------------------

That will work too, and it will be a little more flexible if you have invoice values of varying sizes (ie. multiple commas).

Cheers,

------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

@ewilson
Thanks for your reply!

As I was searching for this for hours. It would benefit others if there's a bit screenshots explaining what​ is discussed here.

1. Set up the Data item

15462.png
2. Set up a collection with "Fields" and "Initial Values"
15463.png
15464.png
3. Set up an action. In the "Regex Pattern", use the correct format "(?<Name (Text)>)RegEx"
* Name (Text), this is what you wrote in the collection initial value
* RegEx, this is normal RegEx pattern
15465.png
15466.png
4. The collection will now have 1 matched result
15467.png


------------------------------
Hao Wu
------------------------------

Hello Hao Wu,
Great initiative compiling the solution.

Made my life easy.



------------------------------
------------------------------
Best Regards,
Ved Sengupta
RPA Developer
Bangalore | INDIA
------------------------------
------------------------------
------------------------------ Best Regards, Ved Sengupta RPA Developer Deloitte India (Offices of the US) Bangalore | INDIA *If you find this post helpful mark it as best answer* ------------------------------