# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^[A-Z\d]\d"
test_str = ("# It's hard to find authoratative notes\n\n"
"01 = Auto accident — the date of an auto accident\n"
"02 = No-fault insurance involved, including auto accident/other — the date of an accident where the state has applicable no-fault liability laws, (i.e., legal basis for settlement without admission or proof of guilt)\n"
"03 = Accident/tort liability — the date of an accident resulting from a third party's action that may involve a civil court process in an attempt to require payment by the third party, other than no-fault liability\n"
"04 = Accident/employment related — the date of an accident relating to the patient's employment\n"
"05 = Other accident — the date of an accident not described by the codes 01 thru 04\n"
"06 = Crime victim — code indicating the date on which a medical condition resulted from alleged criminal action committed by one or more parties\n"
"07 = Reserved for national assignment\n"
"08 = Reserved for national assignment\n"
"11 = Onset of symptoms/illness — the date the patient first became aware of symptoms/illness\n"
"12 = Date of onset for a chronically dependent individual — code indicates the date the patient/bene became a chronically dependent individual\n"
"13 = Reserved for national assignment\n"
"14 = Reserved for national assignment\n"
"15 = Reserved for national assignment\n"
"16 = Reserved for national assignment\n"
"17 = Date outpatient occupational therapy plan established or last reviewed — code indicating the date an occupational therapy plan was established or last reviewed\n"
"18 = Date of retirement (patient/bene) — code indicates the date of retirement for the patient/bene\n"
"19 = Date of retirement spouse — code indicates the date of retirement for the patient's spouse\n"
"20 = Guarantee of payment began — the date on which the provider began claiming Medicare payment under the guarantee of payment provision\n"
"21 = UR notice received — code indicating the date of receipt by the hospital and SNF of the UR committee's finding that the admission or future stay was not medically necessary\n"
"22 = Active care ended — the date on which a covered level of care ended in a SNF or general hospital, or date active care ended in a psychiatric or tuberculosis hospital or date on which patient was released on a trial basis from a residential facility. Code is not required if code \"21\" is used\n"
"23 = Payer only — date of cancellation of hospice benefits — the date the RHHI cancelled the hospice benefit. (eff. 10/2000). NOTE: This will be different than the revocation of the hospice benefit by beneficiaries\n"
"24 = Date insurance denied — the date the insurer's denial of coverage was received by a higher priority payer\n"
"25 = Date benefits terminated by primary payer — the date on which coverage (including worker's compensation benefits or no-fault coverage) is no longer available to the patient\n"
"26 = Date skilled nursing facility (SNF) bed available — the date on which a SNF bed became available to a hospital inpatient who required only SNF level of care\n"
"27 = Date of hospice certification or re-certification — code indicates the date of certification or recertification of the hospice benefit period, beginning with the first two initial benefit periods of 90 days each and the subsequent 60-day benefit periods. (eff. 9/2001)\n"
"27 = Date home health plan established or last reviewed — code indicating the date a home health plan of treatment was established or last reviewed. (Obsolete) not used by hospital unless owner of facility\n"
"28 = Date comprehensive outpatient rehabilitation plan established or last reviewed — code indicating the date a comprehensive outpatient rehabilitation plan was established or last reviewed. Not used by hospital unless owner of facility\n"
"29 = Date OPT plan established or last reviewed — the date a plan of treatment was established for outpatient physical therapy. Not used by hospital unless owner of facility\n"
"30 = Date speech pathology plan treatment established or last reviewed — the date a speech pathology plan of treatment was established or last reviewed. Not used by hospital unless owner of facility\n"
"31 = Date bene notified of intent to bill (accommodations) — the date of the notice provided to the patient by the hospital stating that he no longer required a covered level of IP care\n"
"32 = Date bene notified of intent to bill (procedures or treatment) — the date of the notice provided to the patient by the hospital stating requested care (diagnostic procedures or treatments) is not considered reasonable or necessary\n"
"33 = First day of the Medicare coordination period for ESRD bene — during which Medicare benefits are secondary to benefits payable under an EGHP. Required only for ESRD beneficiaries\n"
"34 = Date of election of extended care facilities — the date the guest elected to receive extended care services (used by Religious Nonmedical Health Care Institutions only)\n"
"35 = Date treatment started for physical therapy — code indicates the date services were initiated by the billing provider for physical therapy\n"
"36 = Date of discharge for the IP hospital stay when patient received a transplant procedure — hospital is billing for immunosuppressive drugs\n"
"37 = The date of discharge for the IP hospital stay when patient received a non-covered transplant procedure — hospital is billing for immunosuppressive drugs\n"
"38 = Date treatment started for home IV therapy — date the patient was first treated in his home for IV therapy\n"
"39 = Date discharged on a continuous course of IV therapy — date the patient was discharged from the hospital on a continuous course of IV therapy\n"
"40 = Scheduled date of admission — the date on which a patient will be admitted as an inpatient to the hospital. (This code may only be used on an outpatient claim.)\n"
"41 = Date of first test for pre-admission testing — the date on which the first outpatient diagnostic test was performed as part of a pre-admission testing (PAT) program. This code may only be used if a date of admission was scheduled prior to the administration of the test(s). (eff. 10/2001)\n"
"42 = Date of discharge/termination of hospice care — for the final bill for hospice care. Date patient revoked hospice election\n"
"43 = Scheduled date of canceled surgery — date which ambulatory surgery was scheduled. (eff. 9/2001)\n"
"44 = Date treatment started for occupational therapy — code indicates the date services were initiated by the billing provider for occupational therapy\n"
"45 = Date treatment started for speech therapy — code indicates the date services were initiated by the billing provider for speech therapy\n"
"46 = Date treatment started for cardiac rehabilitation — code indicates the date services were initiated by the billing provider for cardiac rehabilitation\n"
"47 = Date cost outlier status begins — code indicates that this is the first day the cost outlier threshold is reached. For Medicare purposes, a bene must have regular coinsurance and/or lifetime reserve days available beginning on this date to allow coverage of additional daily charges for the purpose of making cost outlier payments. (eff. 9/2001)\n"
"48 = Payer only — not currently used by Medicare\n"
"49 = Payer only — original Notice of Election (NOE) receipt date\n"
"50–55 = Reserved for state assignment\n"
"56 = Hospice — incorrect date of hospice notification of election (NOE). This code indicates the date of certification or recertification of the hospice benefit period, which has been corrected (the corrected date appears in the record for occurrence code = 26). (eff. 1/2018)\n"
"57–60 = Reserved for state assignment\n"
"61 = Hospital discharge date (HHA only) (eff. 1/2020)\n"
"62 = Other institutional discharge date (HHA only) (eff. 1/2020)\n"
"A1 = Birthdate, insured A — the birthdate of the individual in whose name the insurance is carried\n"
"A2 = Effective date, insured A policy — code indicating the first date insurance is in force\n"
"A3 = Benefits exhausted — code indicating the last date for which benefits are available and after which no payment can be made to payer A\n"
"A4 = Split bill date — date patient became eligible due to medically needy spend down (sometimes referred to as \"split bill date\")\n"
"B1 = Birthdate, insured B — the birthdate of the individual in whose name the insurance is carried\n"
"B2 = Effective date, insured B policy — code indicating the first date insurance is in force\n"
"B3 = Benefits exhausted — code indicating the last date for which benefits are available and after which no payment can be made to payer B\n"
"C1 = Birthdate, insured C — the birthdate of the individual in whose name the insurance is carried\n"
"C2 = Effective date, insured C policy — a code indicating the first date insurance is in force\n"
"C3 = Benefits exhausted — code indicating the last date for which benefits are available and after which no payment can be made to payer C")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html