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
1 Resposta
+ 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"))