For example String is '10S#9D7T*'.
My desire result is 3 arrays. [('10S#'), ('9D'), ('7T*')]
There are 3 condition.
- First one or two digit range is 0~10 always.
- And follow one character is located always.
- And follow
'#'or'*'. But it is not essential.
That is my code.
rex = re.compile(r'\d?\d\w?[\*\#]')
str = '10S#9D7T'
print(rex.findall(str))
Acutal Result -> ['10S#']
There is only one array.
please fixed my regex pattern.
*, and[*#]does not have a?after so you enforce one of these after the match. Just add a*in your string and a?after the[*#]. Note you do not need to escape the*in the brackets.