cancel
Showing results for 
Search instead for 
Did you mean: 

Strings Manipulation and Regex solutions

MayankGoyal2
Level 8
Hi, I have couple of questions regarding string and regex -

1) If I have a String and have to find position of all occurrences of a word (occurrences) in it and return all position in a collection, is there any VBO for the same?
2) If in above case the word to find is not constant, hence I want to define a Regex for it, then find all occurrences of regex in String and return a collection with matched value of String and position (collection with 2 fields) is there any VBO for this?

------------------------------
Mayank Goyal
------------------------------
15 REPLIES 15

You can use Utility - Strings VBO >> Extract Regex Values action for both 1 and 2. You have to pass separate Regex patterns for match and match position.

------------------------------
Pratyush Garikapati
ROM Architect
Blue Prism
Asia/Kolkata
------------------------------

@Pratyush Garikapati ​- Thanks a lot for your response. I tried this action, however I am not able to understand how exactly it works. It is asking for a collection in input which is quite confusing. Saw some online articles as well however not so clear.
consider this example - "BP is a RPA tool, BP has process and objects" and I have to extract word "BP" along with position, not sure how will it happen with "Extract Regex Values"
Another example - "123 is a number, 456 is also a number" and I have to extract numbers with position with regex - "[1-9]+".
For now I wrote a custom code with VB and that is returning me a collection with matching values and position and working fine, however I prefer using standard built in BP VBOs to best possible. Hence kindly suggest how exactly Extract Regex Values works and how can I use it.

------------------------------
Mayank Goyal
------------------------------

In the first example, you are searching for a specific word i.e. "BP". It will probably be easier to use InStr function instead of RegEx, as InStr will provide you the match position directly.

FYI - there are 2 VBOs that provide RegEx actions, but neither of these provide position of match.
https://digitalexchange.blueprism.com/dx/entry/9648/solution/blue-prism-strings-utility
https://digitalexchange.blueprism.com/dx/entry/3593/solution/avoregex

If you want to make your logic generic enough to search for all matches and also return all the positions of match, then you are better off writing your custom VBO. BP recommends that you use existing VBOs if they already have the functionality you need, but you can always extend the VBOs as long as it is reusable.

Extract Regex Values is splitting the Target String using "-" or "to" as the delimiter. The first split goes to Lower row in Named Values collection and second split goes to Upper. This approach works as long as you know the number of matches or if you are doing a split by categories. 


------------------------------
Pratyush Garikapati
ROM Architect
Blue Prism
Asia/Kolkata
------------------------------

Hi Mayank Goyal, 

Thanks for the above information. Can you please help me how did you get all occurrences of a string with positions please ? I have to implement the same thing for my process.

Thanks,
Sushma

------------------------------
Sushma Das
System Analyst
Legal and General
Asia/Kolkata
------------------------------

Hi Sushma,

The current action 'Extract Regex Values' of 'Utility - Strings' VBO has a limitation of extracting any repeated occurrences of a given regular expression match to it since it can only extract the first available regular expression match. Hence, I modified this VBO for one of my use cases in order to get multiple occurrences match. I tweaked the code a bit more as you also need the positions along with the regular expression matches.

You can make a copy of the existing 'Utility - Strings' VBO or make a new custom business object from the scratch. In the 'Initialise' page of your VBO, under the 'Code Options' tab of your Page Description stage be sure to check if you have the following 'Namespace Imports' and 'External References' first with your 'Language' selected as 'Visual Basic'.

External References:

  • System.Data.dll
  • System.Xml.dll
  • System.Drawing.dll

Namespace Imports:

  • System
  • System.Drawing
  • System.Data
  • System.IO
  • System.XML
  • System.Diagnostics
  • Microsoft.VisualBasic
  • System.Data
  • system.text.regularexpressions
  • System.Text
  • System.Collections.Generic
  • Microsoft.VisualBasic.FileIO

30593.png

Now, create a new action called 'Extract Regex Values For Multiple Occurrences' with two input parameters named 'Regex Pattern' of type 'Text' and 'Target String' of type 'Text' along with an output parameter called 'Result' of type 'Collection' and map the data items accordingly.

30594.png

Add a code stage now, called 'Extract Multiple Values' with the below arguments and code:

30595.png

Code:

Dim output As DataTable
Dim regexObj As Regex
Dim currentPosition As Integer

output = New DataTable()
output.Columns.Add("Match Result",GetType(String))
output.Columns.Add("Position",GetType(Integer))

regexObj = New Regex(Regex_Pattern)

currentPosition = 0

For Each matchElement As Match In regexObj.Matches(Target_String)

            currentPosition = Target_String.IndexOf(matchElement.Value, currentPosition+1)
            output.Rows.Add(matchElement.Value,currentPosition)

Next

Result = output

You can now test the same logic either from process studio once you publish this action or from the action page itself. So here I have provided the inputs as follows:

30596.png

And upon running the workflow, my output is as follows:


30597.png

NOTE: The position value here in this collection indicates the position considering that the index starts from 0 and end at 'N-1'. Which means if the text to be searched is at first position for example, then the position would be returned as '0'

------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please provide a big thumbs up so that the others members in the community having similar problem statement can track the answer easily in future.

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Technical Business Analyst,
WonderBotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------

@devneetmohanty07, @Sushma Das,

FYI, the most recent version of the Utility - Strings VBO, available on the DX, includes an action called Extract Regex All Matches which return all matches of a particular pattern, not just the first one. However, it does not include the position of that match. That's something we can add.

I believe this update to the VBO was added last Summer.​

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson,

At my last organization, when we were working on Blue Prism ver.6.4, I faced this issue with the in-house, 'Utility - Strings' business object within the internal VBO folder. Seems like the VBO got updated in DX Exchange and I wasn't aware of that. Though great to know we have the new add-on feature with us now.​​

------------------------------
----------------------------------

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please provide a big thumbs up so that the others members in the community having similar problem statement can track the answer easily in future.

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Technical Business Analyst,
WonderBotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------

@devneetmohanty07,

The DX team have been releasing updates to assets at a much faster rate than what Blue Prism previously was able to do through regular product updates.

I always recommend that users find the DX card for the core assets they use and sign up for notifications when a change is made. 

And for any changes you feel should be made to an existing asset, please let us know via the DX Ideas page. Those changes will be evaluated and added to our backlog where it makes sense.

Cheers,



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi S,

As usual, you do not want to just ask a question and copy/paste the answer without doing any due diligence yourself. To learn more about Regex you might want to check out this site, and why not scan YouTube, or your favorite educational site, for courses on the subject.

------------------------------
Happy coding!
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)