Solved How to use the 'Extract Regex Values' action of Utility - Strings

mdhazlee

New Member
From my understanding, Regex does not seem to allow multiple matches using the same expression to be saved, instead it can save the first captured string that matches the expression. So in your case, using the expression

Code:
(?<=:\s)([\w-]{9,12})

Should identify 3 matches for the claim numbers. But unfortunately you can only write ONE of the match onto the collection (it will be the first claim# in this case). So in order for you to capture all 3, you will need to work the expression from left to right using the following code

Code:
\D*\:\s(?<claim1>[\w-]{9,12}),\D*\:\s(?<claim2>[\w-]{9,12})\D*\:\s(?<claim3>[\w-]{9,12})
 

mdhazlee

New Member
@Gokul-Rpa , I've done a code stage to output multiple matches onto a collection. Insert the following global code into a business object and ensure that the language is changed to C#


Code:
public DataTable MultipleMatchRegex(string input, string regexpression)
{
    DataTable table = new DataTable();
    table.Columns.Add("Regex match", typeof(string));
    Regex regex = new Regex(regexpression);
    foreach (Match match in regex.Matches(input))
        {
        table.Rows.Add(match.Value);
        }
    return table;
}

Remember to include System.Text.RegularExpressions in the Namespace.

In order to use this, insert a code stage with the following RegexMatches = MultipleMatchRegex(Inputstring, Regexpression);

Input will be the input string and pattern, and the output will be an empty collection. After running you will get the matches as attached in my example.

Hope this helps!
 

Attachments

  • Code stage input.PNG
    6.4 KB · Views: 276
  • Code stage output.PNG
    6.2 KB · Views: 250
  • Code.PNG
    6.4 KB · Views: 236
  • Pattern.PNG
    6.5 KB · Views: 233
  • Input.PNG
    8.4 KB · Views: 209
  • Collection output.PNG
    6.4 KB · Views: 214
Last edited:

Rushitv

New Member
@VJR

I've a use case to extract Integer numbers,Can you please help me with the Regex Pattern for the same?

Example: DealShot: General Atlantic Leads $46.7M Series B+ Round In Chinese Convenience Store Operator Today

Wanted to extract 46.7 form the above string.

-Rushit,
 

VJR

Well-Known Member
@VJR

I've a use case to extract Integer numbers,Can you please help me with the Regex Pattern for the same?

Example: DealShot: General Atlantic Leads $46.7M Series B+ Round In Chinese Convenience Store Operator Today

Wanted to extract 46.7 form the above string.

-Rushit,
Are there any preconditions like-
i. Are the numbers always after a $ sign?
ii. How many characters after the $ sign including the dot?
iii. Is there always going to be a decimal?
iv. Is it always going to be followed by the word "Series"?
v. Anything unique like are the numbers always between a '$' sign and a 'M' alphabet?
 

Rushitv

New Member
Are there any preconditions like-
i. Are the numbers always after a $ sign?
Answer: No it may have different currency
ii. How many characters after the $ sign including the dot?
Answer: It It may vary from 1 to 3 characters
iii. Is there always going to be a decimal?
Answer: No, whole number will also be reported
iv. Is it always going to be followed by the word "Series"?
Answer: No
v. Anything unique like are the numbers always between a '$' sign and a 'M' alphabet?
Answer: Mostly start with $ and at the end it could be M or Million
 

VJR

Well-Known Member
Answer: Mostly start with $ and at the end it could be M or Million
In that case you can simply use the Instr function to find the position of the $ sign, extract the remaining text after the $ sign, then find the position of M and get everything in between these two positions.
 

Youssef

New Member
@Gokul-Rpa , I've done a code stage to output multiple matches onto a collection. Insert the following global code into a business object and ensure that the language is changed to C#


Code:
public DataTable MultipleMatchRegex(string input, string regexpression)
{
    DataTable table = new DataTable();
    table.Columns.Add("Regex match", typeof(string));
    Regex regex = new Regex(regexpression);
    foreach (Match match in regex.Matches(input))
        {
        table.Rows.Add(match.Value);
        }
    return table;
}

Remember to include System.Text.RegularExpressions in the Namespace.

In order to use this, insert a code stage with the following RegexMatches = MultipleMatchRegex(Inputstring, Regexpression);

Input will be the input string and pattern, and the output will be an empty collection. After running you will get the matches as attached in my example.

Hope this helps!

Hi mdhazlee,

I have added your solution but i still get the following errors in the initialise code stage:

View attachment 1554824653682.png

You know how to solve this?

Thanks!
 

Rich

Member
There is a good object on the Blue Prism Digital Exchange called Avo.Regex. This object has the action to return multiple Regex results on a string into a collection. works well!
 

xmishaniagx

New Member
Hi Alagupandi,

I know this action is very tricky to understand and there is no documentation explaining about it.
Below are the screenshots.

You need to set a Named Value output parameter in the collection at design time (4.jpg) and then give the same parameter in the actual Regular Expression (2.jpg).

This serves my purpose for an input string of "ABCD123456", but this does not return multiple values in the output collection if the input is something like "ABCD1234XYZ6789". I have been trying to figure out on how it returns multiple matches. If you do find out a way do let me know.

Attn. @Rich : If you have something on multiple outputs please post here. Thanks.

This works great for a single text, with multiple result. however, how can I expend this to multiple text and get each result in a new row? instead of have the results be overridden. TIA
 

rahinik

Member
Yes, My question also nearly the same. I want to extract the same format _abcd in paragraphs whether multiple times also. Any word contains (underscore) _

Please, anyone, help me with this.
 

pln777

New Member
can you please help me with regex for this pattern:
123-456-7789

This particular string (10 digit number separated by -) can appear anywhere in a collection row like: <some text> <tab> 123-262-9282, APR15-MAY15.

I used : (?<Name>\d{3}-\d{3}-\d{4}) but this does not works.


hi,

I think you may found solution , I tried one and want to share this pattern "(?<Number>[\d]+-[\d]+-[\d]+)" but want to remove space b\w text and number

thanks
 
Last edited:

colakvio

New Member
@Gokul-Rpa , I've done a code stage to output multiple matches onto a collection. Insert the following global code into a business object and ensure that the language is changed to C#


Code:
public DataTable MultipleMatchRegex(string input, string regexpression)
{
    DataTable table = new DataTable();
    table.Columns.Add("Regex match", typeof(string));
    Regex regex = new Regex(regexpression);
    foreach (Match match in regex.Matches(input))
        {
        table.Rows.Add(match.Value);
        }
    return table;
}

Remember to include System.Text.RegularExpressions in the Namespace.

In order to use this, insert a code stage with the following RegexMatches = MultipleMatchRegex(Inputstring, Regexpression);

Input will be the input string and pattern, and the output will be an empty collection. After running you will get the matches as attached in my example.

Hope this helps!


Thanks a lot, this solution rocks!!!!
 

Iniotr

New Member
Hi Alagupandi,

I know this action is very tricky to understand and there is no documentation explaining about it.
Below are the screenshots.

You need to set a Named Value output parameter in the collection at design time (4.jpg) and then give the same parameter in the actual Regular Expression (2.jpg).

This serves my purpose for an input string of "ABCD123456", but this does not return multiple values in the output collection if the input is something like "ABCD1234XYZ6789". I have been trying to figure out on how it returns multiple matches. If you do find out a way do let me know.

Attn. @Rich : If you have something on multiple outputs please post here. Thanks.
Hello . I have 2 words ,one is this: "TruNest_m2s_" and the other : "Rinnovo licenze acquisto 2021" .my problem is that regex takes me only the first word....the next one doesnt take it because it has spaces between words but I cant find dhe solution .can you help me ?
 

PMadhavi

New Member
HI
I have the below string and I want to get only the date (5/2/2018). Can you please suggest the regex expression for the same.
Wed 5/2/2018, 4:35 PM
Hello @sakshi
Did you find an expression for a date?
If yes, please post here. I am also having the same question.
My String is "Create Position (Millwright A) - effective 09/07/2021"

Or else anyone can help me to extract date from the above text.
 
Top