Answer the question
In order to leave comments, you need to log in
How to remove square brackets and content using regular expressions?
there is a line from which you need to remove the square brackets and their contents, if inside the brackets there is an integer
I try like this:
import re
s = "one [two] three [1] [2]"
print(re.sub(r'/\[.*?\]/', '', s))
Answer the question
In order to leave comments, you need to log in
re.sub('[\d]', '', s)
For the 128th time, I promise myself to learn regular expressions. And every time I think - "Yes, no, no longer needed!"
>>> import re
>>>
>>> s = "one [two] three [1] [2]"
>>>
>>> re.sub(r'\[\d+\]', '', s)
'one [two] three '
>>>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question