Pull Multiple Data Items - Using RegEx

I am attempting to get multiple items from a text string. I have the following text [example]. My thinking is to match [ACH Credit Received] first and then pull the required information. The data I am trying to pull is in BOLD. In theory we want to not pull anything after “ACH Credit Received Total”

What I have so far is below, but I am having problems grabbing all the information.
ACH\sCredit\s\sReceived\s.\s(\d*,?\d*,?\d+.\d+)

Description Amount (USD)
ACH Credit Received
PEPSI LOGISTICS,CORP PAY,06200001000953
3,423.62 3,423.62

ACH Credit Received
DISNEY LOGISTICS,CORP PAY,062000016164953
5,423.62 3,423.62

ACH Credit Received
CHICAGO LOGISTICS,CORP PAY,0620000920124953
7,423.62 3,423.62

9801156643,0000342362,MHC FINANCIAL SERVICES
ACH Credit Received
MURPHY BROWN,GENERATED,A C H,02015560212358
706,041.57 706,041.57

9801148443,0070604157,FL# 20153000158,MHC
ACH Credit Received Total: 4 Item(s) 709,465.19 .00 .00 709,465.19

Hi,

Hope the following helps you.

Main.xaml (8.1 KB)

Regards,

2 Likes

Hi @etaulton

Answer

import System.Text.RegularExpressions

Assign (String)
pattern = "ACH Credit Received\s+^(?<name>.+?),(CORP PAY|GENERATED,A C H),(?<id>\d+)\s+^(?<amount>\S+)"

Assign (Match)
match = Regex.Match(yourText, pattern, RegexOption.Multiline)

Assign (String)
name = match.Groups(“name”).ToString

Assign (String)
id = match.Groups(“id”).ToString

Assign (String)
amount = match.Groups(“amount”).ToString

Comments

  • You might not need to use a multiline, please test your actual texts with:
    pattern = "ACH Credit Received\s+(?<name>.+?),(CORP PAY|GENERATED,A C H),(?<id>\d+)\s+(?<amount>\S+)"
  • You might want to convert amount to Decimal directly
  • I used ",(CORP PAY|GENERATED,A C H)," because I found a “,” in "GENERATED,A C H" otherwise "[^,]" would have been enough (but with multiline option, like in answer). If you need another term, just add it to the group with another pipe "|" as separator.
  • If the name has a comma, the parsing won’t fail.
2 Likes

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