I am working on a routing project. The route looks like this "CNSHG(B)-PAMIT(R)-COCTG(B)-USHOU(R)-COCTG(B)-USMSY" and I want to break it into a nested list. Also, a route contains multiple segments for example CNSHG-PAMIT is one segment transported using B and then PAMIT-COCTG transported using R i.e, Rail, and so on.
Input:
"CNSHG(B)-PAMIT(R)-COCTG(B)-USHOU(R)-COCTG(B)-USMSY"
The output should be like this:
[[CNSHG, PAMIT, B],[PAMIT, COCTG, R],[COCTG, USHOU, B],[USHOU, COCTG, R],[COCTG, USMSY, B]]
I have tried using regex and the below codes but it didn't work.
route.str.extract('(.)\s\((.\d+)')
Thanks a lot.
(.\d+)? There are no digits in your input.USMSYdoesn't have a means of transportation following it (B,R, or something else). Will that always be the case?