Advanced RegEx Matching [1 or 2]

Good day,
I have another advanced Regex task I am trying to match with UiPath. In the following example, I am trying to match each [GROUP] occurrence of the following: Amount & Organization
They may occur multiple times so I need to match each group. I have included sample text below. I have been able to match the TAG Incoming Money Transfer. It should stop when reading the text [Incoming Money Transfer Total]

  • Incoming Money Transfer\s*.\s.\s(?[^\s+][,0-9[.0-9{2}]+)-
    Any help is appreciated.

Sample text:

ACH Credit Received Total: 3 Item(s) 210,089.79 .00 .00 210,089.79

Incoming Money Transfer 000131 200665487523

16:24
1,525.84 1,525.84

SND= 081298940 MIDLWEST STATES BANK
SBR= 20076711523
RCV= 1019346985 UMB BANK NA
TYP= FED*
BBK= 9843248443MHC FINANCIAL SERVICES INC
19920 TWO CREEK PKWY SUITE 200LEAWOOD, KS 662112695
BNF= G9898146543MGG FINANCIAL SERVICES8501 BOSTON BLVD*
LEAWOOD, KANSAS 66211*
ORG= BGL ENTERPRISES INC605 S GREENWOOD AVEKANKAKEE IL 60901-0000*

Incoming Money Transfer 001155 200604000131

05:06
2,002.00 2,002.00

SND= 17721980248 WELLS FARGO BANK NATL ASSOCIATION
SBR= 20009348080131
RCV= 1099002235 UMB BANK NA
TYP= FED*
BBK= 989031767443MHC FINANCIAL SERVICES INC
41010 TOMAHAWK ROAD SUITE 200LEAWOOD, KS 662112695
BNF= D9221198441843MHC43MGG FINANCIAL SERVICES INC1008 OAK ST
ST LOUIS MO 64106*
RFB= OW000891265678325*
ORG= KEITH D ANDERSON1537 NEWCASTLESTREAM DRDESOTO TX 751156105US
OBI= 131800987

Incoming Money Transfer 013462 200604009408

15:19
41,307.92 41,307.92

SND= 02600454999312 BANK OF AMERICA NV
SBR= 29960564678948
RCV= 12300789951 UMB BANK NA
TYP= FED*
BBK= 97661183243MGG FINANCIAL SERVICES INC
55620 TWO WINGS PKWY SUITE 200LEAWOOD, KS 662112695
BNF= E980GT48773MGG FINANCIAL SERVICESKANSAS CITYMISSOURI 64108 US
RFB= YPNH875N98KZU*
ORG= WILLIAMS BROTHERS CONCRETE AND MASONPO BOX 18949BULONNC 275970249 US
OGB= BBOZEFA678USNM3NBANK OF AMERICA, N.A.222 BROADWAYNEW YORK,NY,US
OBI= GOODSOLD

Incoming Money Transfer 013081 200604009367

15:17
66,292.59 66,292.59

SND= 026S342PP9893 BANK OF AMERICA NV
SBR= 2018890Z06511A67
RCV= 10100990BB695 UMB BANK NA
TYP= FED*
BBK= 9801ZSS149980013GGG FINANCIAL SERVICES INC
78780 CREEK PKWY SUITE 200LEAWOOD, KS 662112695
BNF= Y732098148993GGG FINANCIAL SERVICESKANSAS CITYMISSOURI 64108 US
RFB= 9PRS287BPR*
ORG= WILLIAMS JAMES CONCRETE AND MASONPO BOX 009249ZELONNC 275970249 US
OGB= BBOFAZA88US3NBANK OF AMERICA, N.A.222 BROADWAYNEW YORK,NY,US
OBI= GOODS

Incoming Money Transfer Total: 4 Item(s) 111,128.35 .00 .00 111,128.35

MHCFS UiBOT Page 1 of 2 06/05/2020 14:01

Well, the Amount is quite easy to extract but can you be sure your Organization will not contain any digit?

EDIT: or can you match easily the address on the ORG line? (the PO BOX is obvious but the others?)
EDIT2: I notice the italics and the paging: you might have a great help from the document structure. What kind of source is it? HTML?

Yes, I think the program changed the formatting a little.

  1. Yes can assume company will NOT contain numbers
  2. The company name actually ends with an * - not shown in the text but is present in extracted text

Then (you can adapt to make amount directly a Decimal, etc.),

import System.Text.RegularExpressions

Assign (String)
pattern = "^\d{2}:\d{2}\s+^(?<amount>[\d,\.]+).+?^ORG=\s+(?<organization>.+?)(\d|PO BOX)"

Assign (MatchCollection)
matches = Regex.Matches(sample, pattern, RegexOption.Multiline Or RegexOption.Singleline)

ForEach match in maches (ArgumentType is Match)

  • Assign (String)
    amount = match.Groups("amount").Value.ToString

  • Assign (String)
    organization = match.Groups("organization").Value.ToString

EDIT: you might want to try this if the “*” ends company name and no company name has this in its name:

pattern = "^\d{2}:\d{2}\s+^(?<amount>[\d,\.]+).+?^ORG=\s+(?<organization>.+?)\*"

EDIT2: a little trick to avoid using singleline option:
pattern = "^\d{2}:\d{2}\s+^(?<amount>[\d,\.]+)[\s\S]+?^ORG=\s+(?<organization>.+?)\*"

EDIT3: and another one to avoid both Singleline and Multiline:
pattern = "\d{2}:\d{2}\s+(?<amount>[\d,\.]+)[\s\S]+?ORG=\s+(?<organization>.+?)\*"
matches = Regex.Matches(sample, pattern)

Thanks, but I have to keep the Incoming Money Transfer in the RegEx as the statement will contain other transaction information, but I only want the $$ and Company for the Incoming Money Transfer

pattern = "Incoming Money Transfer[\s\S]+?\d{2}:\d{2}\s+(?<amount>[\d,\.]+)[\s\S]+?ORG=\s+(?<organization>.+?)\*"