I have a huge string which contains a lot of numbers in square brackets. For instance:
[1] this is an example ... [123] another example
How can I remove the numb
Try using re.sub:
re.sub
import re text = txtFile.read() text = str(text) text = re.sub(r'\[\d+\]', '', text)
The regex pattern \[\d+\] should match any bracket term which has one or more numbers in it.
\[\d+\]
Note that re.sub by default will do a replacement against the entire input string.