when I call re.findall(x, "s)s)s") for x = r”)” it returns an error. Is there a way to make it not do that? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

when I call re.findall(x, "s)s)s") for x = r”)” it returns an error. Is there a way to make it not do that?

“”” I know the parentheses are unbalanced but it seems like it should just print a list of every “)” in the string. “”” import re patt1 = r"s" patt2 = r")" a = int(input()) if a % 2 == 0: x = patt1 else: x = patt2 print(re.findall(x, "s)s)s")) https://code.sololearn.com/cXg04479cP9u/?ref=app

15th Sep 2019, 12:40 AM
Evan
1 Answer
+ 1
The parenthesis '(' and ')' are special characters in regex. To match them use '\(' or '\)', or enclose them inside a character class: '[(]', '[)]'. https://docs.python.org/3.7/library/re.html#index-14 patt2 = r"\)" print(re.findall(x, r"s\)s\)s"))
15th Sep 2019, 3:54 AM
Diego
Diego - avatar