Created
October 2, 2019 19:58
-
-
Save ixe013/4c12e038af344b798552ba36a3a61b4c to your computer and use it in GitHub Desktop.
Converts a AAR EMP address to a locomotive id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
emp = 'cn.l.ble.901:itc' | |
#Test regex here: | |
#https://pythex.org/?regex=%5E(%5Ba-z%5D%7B2%2C4%7D)%5C.l%5C.(%5Ba-z%5D%2B%3F)%5C.(.*)%3A(.*)&test_string=cn.l.ble.901%3Atmc | |
pattern = re.compile(r'^([a-z]{2,4})\.l\.([a-z]+?)\.(.*):(.*)') | |
match = pattern.search(emp) | |
scac, origin, number, topic = match.groups() | |
#print(scac, origin, number, topic) | |
print(f'emp={emp}') | |
print(f'locoid={origin}{number}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment