import re
regex = re.compile(r"""
(\${2}[A-Z]{4}, #Callsign
\d+, #line number
\d{2}:\d{2}:\d{2}, #time (hh:mm:ss)
-?\d+\.\d+, #latitude
-?\d+\.\d+, #longitude
\d{5}, #altitude
\d+, #a
\d+, #b
\d+, #c
[\d.]+, #d
[\d.]+, #e
\d{3}\*[0-9A-Z]{4}) #checksum
|(^.*$\R*)
""", flags=re.VERBOSE | re.MULTILINE)
test_str = ("$$CALL,1659,14:13:24,40.84870,-113.69349,07916,107,58,12,32.9,4.1,175*C3F1\n"
"$$CALL,1660,14:13:26,40.84898,-113.69292,07929,100,58,12,32.9,4.1,175*54DC\n"
"$$CALL,1661,14:13:29,40.84939,-113.69206,07950,111,57,12,32.9,4.1,175*DDB6\n"
"$$CALL,1662,14:13:32,40.84982,-113.69109,07969,111,62,12,32.9,4.1,175*1E13\n"
"$$CALL,1663,14:13:3,07985,105,74,12,32.9,4.1,175*A9EF\n"
"$$CALL,1664,14:13:37,40.85025,-113.68941,07995,105,68,12,32.9,4.1,175*11F1\n"
"$$CALL,1665,14:13:40,40.85052,-113.68848,08012,91,76,12,32.9,4.1,175*3B4E\n"
"$$CALL,1666,14:13:43,40.85069,-113.68761,08030,81,72,12,32.9,4.1,175*3602\n"
"$$CALL,1667,14:13:46,40.85096,-113.68690,08052,83,58,12,32.9,4.1,175*A4FA\n"
"$$CALL,1668,14:13:48,40.85120,-113.68639,08067,102,53,12,32.8,4.1,175*6800\n"
"$$CALL,1669,14:13:51,40.85166,-113.68555,08082,109,56,12,32.8,4.1,175*C94E\n"
"$$CALL,1670,14:13:54,40.85206,-113.68465,08100,104,61,12,32.8,4.1,175*C711\n"
"$$CALL,1671,14:13:56,40.85232,-113.68404,08113,102,63,7,32.8,4.1,175*8E14\n"
"$$CALL,1672,14:13:59,40.85268,-113.68312,08137,72,54,12,32.8,4.1,175*F764\n"
"$$CALL,1673,14:14:02,40.85302,-113.68250,08153,81,54,12,32.8,4.1,175*7EB7\n"
"$$CALL,1674,14:14:05,40.85335,-113.68174,08173,89,68,12,32.868117,08183,98,73,12,32.8,4.1,175*3AF2\n"
"$$CALL,1676,14:14:10,40.85373,-113.68022,08201,113,63,12,32.8,4.1,175*63EF\n"
"$$CALL,1677,14:14:13,40.85410,-167922,08215,109,64,12,32.8,4.1,175*7E0D\n"
"$$CALL,1678,14:14:16,40.85447,-113.67825,08234,107,60,12,32.8,4.1,175*7BDB\n"
"$$CALL,1679,14:14:18,40.85475,-113.67764,08250,109,63,12,32.8,4.1,175*1F6C\n"
"$$CALL,1680,14:14:21,40.85508,-113.67664,08267,100,73,12,32.8,4.1,175*8BB9\n"
"$$CALL,1681,14:14:24,40.85531,-113.67574,08284,89,66,12,32.7,4.1,175*0A7C\n"
"$$CALL,1682,14:14:27,40.85557,-113.67497,08299,81,66,12,32.7,4.1,175*138C\n"
"$$CALL,16835575,-113.67449,08311,85,55,12,32.7,4.1,175*AE98\n"
"$$CALL,1684,14:14:32,40.85613,-113.67379,08331,85,54,12,32.7,4.1,175*45B3\n"
"$$CALL,1685,14:14:35,40.808354,81,66,12,32.714:14:38,40.85667,-113.67230,08369,85,70,12,32.7,4.1,175*D7F9\n"
"$$CALL,1687,14:14:40,40.85684,-113.67173,08378,100,67,12,32.6,4.1,175*CC36\n"
"&,1688,14:14:43,40.85712,-113.67080,08397,100,67,12,32.6,4.1,175*D678\n"
"$$CALL,1689,14:14:46,40.85740,-113.66988,06,4.1,175*787C\n"
"$$CALL,1690,14:14:48,40.85758,-113.66923,08425,111,66,12,32.6,4.1,175*5F8E\n"
"$$CALL,1691,66824,08444,113,61,12,32.6,4.1,175*D33A\n"
"$$CALL,1692,14:14:54,40.85836,-113.66721,08460,115,58,12,32.6,4.1,175*9867\n"
"$$CALL,1693,14:14:57,40.85880,-113.66629,08484,100,57,12,32.6,4.1,175*2A74\n"
"$$CALL,1694,14:15:00,40.85916,-113.66546,08510,92,61,12,32.6,12,32.6,4.1,175*7F6$$CALL,1696,14:15:05,40.85997,-113.66428,08542,1\n"
"15,55,12,32.6,4.1,175*DBA2\n"
"$$CALL,1697,14:15:08,40.86042,-113.66332,08567,104,61,12,32.6,4.1,175*392B\n"
"$$CA14:15:13,40.86094,-113.66180,08595,126,58,12,32.6,4.1,175*ABC7\n"
"$$CALL,1700,14:15:16,40.86145,-113.66080,08609,107,54,190,-113.65989,08628,113,61,12,32.5,4.1,175*D97E")
subst = "$1"
result = regex.sub(subst, test_str)
if result:
print(result)
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