Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I am fairly new to using regex expressions. I am trying to parse some EDI data. My match pattern looks like the following:
trn(?<ed>.).{1,2}\k<ed>(?<ref>.{1,30})(\k<ed>.{10,10}|\k<ed>.{10,10}\k<ed>.{1,30})?(?<sd>.{0,1})

For this specific string of data, I have up to 4 element fields that are separated by an element delimiter. The string will always contain "TRN" followed by the element delimiter, up to 4 element fields, and a segment delimiter. I added an ed backreference for the element delimiter, an ref backreference for the 2nd element field, and an sd backreference for the segment delimeter. The 1st and 2nd element fields are required whereas the 3rd and 4th element fields are optional. The element and segment delimiters should never be the same.

Sample String Value:705TRN*1*811269480000000*1000033492\ 066636640 00018932955

1:First element field. Length can be 1 to 2 chars with a mixture of numbers or letters.

*: element field delimiter.

811269480000000: 2nd element field. Length can be 1 to 30 chars.

1000033492: 3rd element field. Length is 10.

\: Should be the segment delimiter but for some reason it is pulling the 6.

066636640 00018932955: Extra information that is being passed that I do not care about.

Here is the match information that I am getting. I am expecting the ref backreference to just be referencing 811269480000000 and not the whole value of the element delimiter and the 3rd element field. Can someone please help me figure out what I am doing wrong? The element delimiter should always be the same value throughout the whole string. Please let me know if you need for me to provide you with any other information. Thanks in advance for your help!
Match:TRN*1*811269480000000*1000033492\ 06
element delimiter:*
segment delimeter:6
ref:811269480000000*1000033492\ 0
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900