You should use re.finditer
instead of re.findall
and then print the whole matching group:
>>> for m in re.finditer('(ra|RA)[a-zA-Z0-9]*',"RAJA45909"):
... print(m.group())
...
RAJA45909
The documentation of findall
says:
If one or more groups are present in the pattern, return a list of
groups; this will be a list of tuples if the pattern has more than one
group.
Your regex has only one group and thus the result is a list of texts matched by that single group. If we add an other group you see:
>>> for m in re.findall('(ra|RA)([a-zA-Z0-9]*)',"RAJA45909"):
... print(m)
...
('RA', 'JA45909')
So findall
when used with groups matches the whole regex but only returns the portions matched by the groups. While finditer
always returns a complete match object.