What I would like my result to be is throughout all the text file look between the “~TRN1” and the next “*” and only show the last 4 characters between, so the end result would just show the following:
By reading your setup, it has helped me get closer…
The Regex output result is where i am getting jammed up
All i want is what is in bold. Let me know if you need more info and thank you!
what i currently get:
{~TRN110100000000}
{~TRN110100000001}
{~TRN110100000002}
{~TRN110100000003}
{~TRN110100000004}
{~TRN110100000005}
{~TRN110100000006*}
In Olaf’s regex he uses a capture group and the key element is placing the “*” right after the capture group. This pretty much describes that the 4 digits he wants in the capture group “(\d{4})” come right before the asterisk in the sample text.
Personally I prefer to name my capture groups if ever I use capture groups then you can access them via $matches[“name”] rather than a numerical index.
The text file I have does not have any spaces but is using ‘*’ for all the spaces if that makes sense. For example a small segment on how the text file is:
ACHCCP01111DA331234567890**01111DA2220100101~TRN1101000000001000000000~REFEVETIN~DTM40520100101~N1PRNYSDOH~N3OFFICE OF HEALTH INSURANCE PROGRAMSCORNING TOWER, EMPIRE STATE PLAZA~N4ALBANYNY122370080~PERBLPROVIDER SERVICESTE8003439000URwww.emedny.org~N1PEMAJOR MEDICAL PROVIDERXX9999999995~REFTJ000000000~LX1~CLPPATIENT ACCOUNT NUMBER134.2534.25**MC100021000000003011~NM1QC1SUBMITTED LASTSUBMITTED FIRSTMILL99999L~NM1741CORRECTED LASTCORRECTED FIRST~REFEAPATIENT ACCOUNT NUMBER~DTM232*20100101~DT
Now this text file may have multiple ~TRN1 in it which can vary in numerical length. I want to grab the last four numbers Between ~TRN1 and the following ‘*’ for every instance that it can be found in this text file. (forgive me guy’s, I am new to a lot of this and i am trying to understand. So if i am missing something just please let me know) I appreciate all the help!
This is the result i have:
0580
0580
0580
0580
0580
0580
0580
0580
0580
This is a small example of the text document and how it is layed out:
ACHCCP01111DA331234567890**01111DA2220100101~TRN1101000000001000000000~REFEVETIN~DTM40520100101~N1PRNYSDOH~N3OFFICE OF HEALTH INSURANCE PROGRAMSCORNING TOWER, EMPIRE STATE PLAZA~N4ALBANYNY122370080~PERBLPROVIDER SERVICESTE8003439000URwww.emedny.org~N1PEMAJOR MEDICAL PROVIDERXX9999999995~REFTJ000000000~LX1~CLPPATIENT ACCOUNT NUMBER134.2534.25MC100021000000003011~NM1QC1SUBMITTED LASTSUBMITTED FIRSTMILL99999L~NM1741CORRECTED LASTCORRECTED FIRST~REFEAPATIENT ACCOUNT NUMBER~DTM23220100101~DTM23320100101~AMTAU34.25~SVCHC:V2020:RB661~DTM47220100101~AMTB66~SVCHC:V2700:RB2.752.75**1~DTM47220100101~AMTB62.75~SVCHC:V2103:RB5.55.51~DTM47220100101~AMTB65.5~SVCHC:S058020*202~DTM47220100101~AMTB6
I just want to find all the numbers between every ~TRN1 and the next asterisk found in the text file. and only display the last 4 sets of numbers regardless of the length between the numbers, i just need it to always be the last 4. Thank you all so much for your assistance with this, i am a total newbie at this and trying to learn.
This is what the text file looks like (small sample but throughout):
ACHCCP01111DA331234567890**01111DA2220100101~TRN1101000000001000000000~REFEVETIN~DTM40520100101~N1PRNYSDOH~N3OFFICE OF HEALTH INSURANCE PROGRAMSCORNING TOWER, EMPIRE STATE PLAZA~N4ALBANYNY122370080~PERBLPROVIDER SERVICESTE8003439000URwww.emedny.org~N1PEMAJOR MEDICAL PROVIDERXX9999999995~REFTJ000000000~LX1~CLPPATIENT ACCOUNT NUMBER134.2534.25MC100021000000003011~NM1QC1SUBMITTED LASTSUBMITTED FIRSTMILL99999L~NM1741CORRECTED LASTCORRECTED FIRST~REFEAPATIENT ACCOUNT NUMBER~DTM23220100101~DTM23320100101~AMTAU34.25~SVCHC:V2020:RB661~DTM47220100101~AMTB66~SVCHC:V2700:RB2.752.75**1~DTM47220100101~AMTB62.75~SVCHC:V2103:RB5.55.51~DTM47220100101~AMTB65.5~SVCHC:S058020*202~DTM47220100101~AMTB6
The results are showing now! Thank you, thank you, thank you! You have been a overwhelmingly great help Olaf!
To be more specific on why I was trying to figure this out. I work in Ambulance Billing and I receive these Electronic Remittance Advices (ERAs) that are supposed to be opened in a application called Medicare EasyPrint reader. These files come in the file extension of .EDI (example.EDI). What I am currently having to do is open these files one by one and rename them based on the insurance payor and the check numbers contained within, sometimes a single check number, other times a whole bunch of check numbers, but only the last 4 digits of each check number. What I figured is since this is a repetitive task, I could use powershell to automate this process. Eventually I would like to run a powershell script, that will pull that information within each EDI file and rename them based upon those specific matches you have assisted me so awesomely with Olaf and I thank you soooooo much for that!
I didn’t want to tell everyone what the bigger picture was because I didn’t want someone to just make the whole thing for me or people thinking I wanted them to do this for me, I am trying to study and understand everything being used and you have given me enough to study with the code you provided me Olaf.
Also since these files come in .EDI File extension, I just mass change them to the .txt extension to make it readable which is the sample result I gave you, all in one line only.