how to match a number followed immediately by either /tcp or /udp or nothing?
the following illustrates 3 scenarios: input --> result
- 123/tcp_haha --> 123
- 123 --> 123
- 123abc/tcp --> no match
i used re.compile(r'(\d+)(?:\/[tcpud]{3})*')but it also matched in case 3.
EDIT: Guess it's really a follow up question: how to match digits either followed by /tcp or /udp or proceeded by tcp/ or /udp or just by itself? so
1. something else 123/tcp_haha --> 123
2. 123 --> 123
3. 123abc/tcp --> no match
4. udp/123 something else --> 123
5. tcp/123/tcp --> 123