Feb-25-2019, 08:00 AM
Hello.
Given an input like "1234abd-alknfsdan-asjkldn-asd" I want to be able to see if there are 4 digits at the start followed by a specific substring. In this case we will use abd. As in the given example, I want to be able to see that the string starts with 4 digits, then is followed by "abd". In this case it passes.
So far I can only match if there are digits in the string at all, not worrying about where. How can I go about this?
P.S.
Just to clarify, these are the requirements:
Given an input like "1234abd-alknfsdan-asjkldn-asd" I want to be able to see if there are 4 digits at the start followed by a specific substring. In this case we will use abd. As in the given example, I want to be able to see that the string starts with 4 digits, then is followed by "abd". In this case it passes.
So far I can only match if there are digits in the string at all, not worrying about where. How can I go about this?
import re string = "1234ict-asdasd-asdasd" print(bool(re.search(r'\d', string)))Thanks :)
P.S.
Just to clarify, these are the requirements:
- 4 (no more, no less) digits at the start of the string.
- Followed by a given string, it can be anything I want