Skip to content

Instantly share code, notes, and snippets.

@ixe013
Created October 2, 2019 19:58
Show Gist options
  • Save ixe013/4c12e038af344b798552ba36a3a61b4c to your computer and use it in GitHub Desktop.
Save ixe013/4c12e038af344b798552ba36a3a61b4c to your computer and use it in GitHub Desktop.
Converts a AAR EMP address to a locomotive id
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