I am trying to look for a string of the form '[123]' in a given string but I'm not expecting the result I'd want to see i.e. '[123]'.
line = '[123] some string'
words = line.split()
for word in words:
id = re.sub("\[(\d+)\]", "", word)
print id
This gives me the output:
empty space
some
string
I'm unsure why re.sub() is formatting my correctly matched string '[123]' this way.