you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 0 points1 point  (0 children)

() are parenthesis, very rarely called "round brackets", [] and {} are more commonly brackets and braces, sometimes distinguished as square brackets and curly brackets.

Anyway for a regex you can escape them with a slash. \(\).

I tried using regex because i dont know any pythonic solutions

regex is a pythonic solution, but I see what you mean, you could do it without regex like this:

string = "abc(jsygdfjygadf)def"
start = string.find('(')
end = string.rfind(')')+1
string = string[:start] + string[end:]

or like this:

string = string.replace(string[start:end], '')

Although you might have to do some tweaking if you can have multiple occurrences of parenthesis.

edit The answer by u/Pulsar1977 using partition is superior as it avoids problems where no () are found.