0

What is the regular expression for matching a sentence that contains a parentheses ?

Following the senario :

I have a string : line = "He finally answer (after taking time to think(5 minutes))"

I want to match this part of the sentence : after taking time to think(5 minutes)

But i don't want to use a regex to find the element inside of parentheses

For that I am using : re.search("after taking time to think(5 minutes)",line)

But I'm getting the result None

And I think that my problem come from the parentheses

Julia
  • 11
  • 2
  • `(` and `)` belong to special regex metacharacters, you need to escape them if you want to use them as literal parentheses in a regex pattern. If it is dynamic, use `re.escape(your_var)` – Wiktor Stribiżew Sep 07 '21 at 16:23

0 Answers0