using regex in python to find strings which starts with exactly N digits? [closed]

I should tag my strings if they start with two digits as 'basic', and the ones that start with 5 digits as 'complex'. for example:

11abc is 'basic'

12345ad is 'complex'

22 is'basic'

can anyone help me with it, please?


Solution 1:

The easiest way would be to just check where the string begins.

str_ = "..."
if not str_[2].isdigit():
    # basic
elif not str_[5].isdigit():
    # complex

Assuming that your strings always have 2 or 5 digits at the start, which seems to be the case based on your question.