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
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.
Add a code stage now, called '
Extract Multiple Values' with the below arguments and code:
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:
And upon running the workflow, my output is as follows:
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 this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.