I have an EDI file whose structure is given below. This file has multiple records, each record contains a header(e.g EDI.DD.0000000001.20130809), then contents (i.e multiple paragraphs of text) and then footer (e.g End of Report/No EDI Activity). I have to read that entire file using regular expression using three groups.
I am using following regular expression to read the file.
(?<header>[A-Z]{3}.[A-Z]{2}.[0-9]{10}.[0-9]{8}) | (?<footer> \b(End\sof\sReport|No\sEDI\sActivity)\b) |
(?<content>(?<=\k<header>).*(?=\k<footer>))
That expression reads the "header" and "footer" in respective groups properly but didn't pick the contents between header and footer in "contents" group.
I have changed the font of header and footer in below file to help to understand the format. I am using asp.net 3.5 framework.
Thanks for your help in advance.
//------------------Start of EDI File---------------------// EDI.DD.0000000001.20130809
ORIGINATOR INFORMATION Company Name: UNITED HEALTHCAR Identification: 9024125001 Originating DFI: 002100002
RECEIVER INFORMATION Receiver Name: HEALTH & WELLNESS DFI Account Number: 0000000000000001 Receiving DFI ID: 434343430 ID Number: Transaction Type: 22 Deposit
ORIGINATOR INFORMATION Company Name: BLUE CHOICE Identification: 9024125001 End of Report EDI.DD.0006578987.20130809 No EDI Activity EDI.SV.0000000555.20130809
ORIGINATOR INFORMATION Company Name: Univ of Florida Identification: A426004813 Originating DFI: 004200001
TRANSACTION INFORMATION
Entry Description: vndr pymnt Entry Class Code: CTX Service Class Code: ACH Entries Mixed
REMITTANCE ADVICE ACCOUNTS
RECEIVABLE OPEN ITEM REFERENCE
Seller's Invoice Number: 10016 Pmt Action Code: Amount Paid: $800.00 Amount of Invoice: Amount of Discount: End of Report
//--------------------End of file------------------------//
1 2029
Note: (?<contents>.*?) -- This is a non-greedy match meaning the .* does not try to match the whole string. The RegexOptions.Singleline option treats the input to the Matches function as one long string instead of multiple lines. - Regex re = new Regex(
-
"(?<header>[A-Z]{3}.[A-Z]{2}.[0-9]{10}.[0-9]{8})" +
-
"(?<contents>.*?)" +
-
"(?<footer>(End of Report|No EDI Activity))",
-
RegexOptions.Singleline);
-
-
MatchCollection matches = re.Matches(fileData);
-
-
foreach(Match m in matches) {
-
Console.WriteLine("Header: {0}, Body Length: {1}, Footer: {2}",
-
m.Groups["header"].Value,
-
m.Groups["contents"].Value.Length,
-
m.Groups["footer"].Value);
-
}
Run results: - Header: EDI.DD.0000000001.20130809, Body Length: 356, Footer: End of Report
-
Header: EDI.DD.0006578987.20130809, Body Length: 4, Footer: No EDI Activity
-
Header: EDI.SV.0000000555.20130809, Body Length: 403, Footer: End of Report
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Axel Kowald |
last post by:
Hi everybody,
I have a 'simple' problem with regular expressions. Maybe someone can
help me.
import re
bla = 'the the'
obj = re.search('(.+) \1',bla)
obj.group(1) should now be 'the'....
|
by: googlinggoogler |
last post by:
Hiya,
The title says it all really, but im a newbie to python sort of. I can
read in files and write files no probs.
But what I want to do is read in a couple of files and output them to
one...
|
by: Clunixchit |
last post by:
How can i read lines of a file and place each line read in an array?
for exemple;
array=line1
array=line2
...
|
by: Arjen |
last post by:
Hi,
If the users enters some data it must be have 1 ... 100 characters. These
characters may be placed on multiple lines. (textbox)
I use this: .{1,100}
But this only works with one line.
...
|
by: Sreedhar Vankayala |
last post by:
Hi,
I have a simple textbox in a form page.
- If data not available, then user can enter the text "Not available"
or "Contact abc person".
- If data is available, then user enters the data...
| |
by: teo |
last post by:
I have a problem (partial).
Some days ago I asked for a way
to extract a word and few text around it
(30 chars on the left and 30 on the right)
from a long text.
I went good with:
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |