Regex issue - "unbalanced parenthesis at position"

Dear All,

Hope everyone of you are having a great day.

my line of coding is below ( and this worked without any issue ),

checker = re.compile(".*s$")

but now I am dealing with a bracket after the letter “s” and when I coded as below :

checker = re.compile(".*s)$")

I am getting the below error,

“unbalanced parenthesis at position”

Can someone please be kind enough to help me out.

Thank you.

That’s because parenthesis can have special meaning inside of regex pattern. To use it or other characters that are special in regex, in their typical meaning, they need to be escaped with \. In case of ), escaped version would be \).

It worked.
You’ve restored my Sanity bud :heart_eyes: :heart_eyes: :heart_eyes:

Thanks a lot,
May you be guided in your life.

Take care bud.

P.S - I am a self learner so I do not understand much of the basics. Thank you again.

1 Like