What's a fast way in Python to take all the characters included between two specific characters out of a string?
What's a fast way in Python to take all the characters included between two specific characters out of a string?
You can use this regular expression: \(.*?\)
. Demo here: https://regexr.com/3jgmd
Then you can remove the part with this code:
import re
test_string = 'This is a string (here is a text to remove), and here is a text not to remove'
new_string = re.sub(r" \(.*?\)", "", test_string)
This regular expression (regex) will look for any text (without line break) in brackets prepended by a space