Regex continuation pattern

I have two kinds of text statements

  1. Payment of Import Bill is 34$ to ABC Party

  2. Payment of Import Bill is 56$ to DEF party and Payment of Import Bill is 67$ to IJK Party

Now what I want to do is write a regex pattern which will recognize the text as type A if the words “Payment of Import Bill” all 4 are in continuation and in order appear once

Same If the words “Payment of Import Bill” all 4 are in continuation and in order appear twice the regex should recognize the text as type B

So in the above 2 example statements the first statement should be detected as type A and the second statement should be detected as type B

Any help is appreciated

@Ishan_Shelke

You dont need a regex for this.you can use a split and then count the results to know if one two or n are present

Say the string is in str variable

Str.Split({"Payment of Import Bill"},StringSplitoptions.RemoveEmptyEntries).Count

Cheers

Hi @Anil_G , This is the text file which I am reading the data from the below text file though there are only 2 occurrences UiPath shows it as 3

documenttext1.txt (372 Bytes)

image

Hi @Ishan_Shelke

Try with this expression

System.Text.RegularExpressions.Regex.Matches(YourString.trim,"PAYMENT OF IMPORT BILL").Count

image

Regards
Gokul

Hi @Ishan_Shelke

Str.Split({"Payment of Import Bill"},StringSplitoptions.None).Count

This will always give the count as +1 …so always from result you have to remove 1 to get the count…Basically it counts the number of splits happened which will be plus one of the split keyword

cheers

Hi @Ishan_Shelke ,

Use if condition
System.Text.RegularExpressions.Regex.Matches(YourString.trim,"(?i)\bPAYMENT OF IMPORT BILL\b").Count=2

If Yes consider as B, else consider A

Regards,
Arivu

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.