You have done 'tab'
and not tab
. One is a string, another is a variable. You want to do re.findall(tab, line)
(see how tab is no longer a string). You also did this for line
.
However, if you print tab
beforehand, you'll notice you have:
a-z0-9
When I think you're intending to have
[a-z0-9]
So you can concatenate strings:
>>> print re.findall('['+tab+']',line) # Here we add a bracket to each side
# of a-z0-9 to create a valid regex
# capture group [a-z0-9]
['a', 'n', 'd', 't', 'h', 'e', 'n', '3', 't', 'i', 'm', 'e', 's', 'm', 'i', 'n', 'u', 's', '4', '5', '6', 'n', 'o', 'm', '0', 'r', 'e']
Or you can use str.format()
:
>>> print re.findall('[{}]'.format(tab),line)
['a', 'n', 'd', 't', 'h', 'e', 'n', '3', 't', 'i', 'm', 'e', 's', 'm', 'i', 'n', 'u', 's', '4', '5', '6', 'n', 'o', 'm', '0', 'r', 'e']