我正在尝试解析用单引号括起来的字符串。
对于输入:Redditor(user_name ='abc')
我的输出应该是:abc
这是按预期工作的:
text = "Redditor(user_name='abc')"
author = re.findall(r'\'(.+?)\'', text)
print(author)
这不是:
text = str(x.author) #I am getting x.author from API call. If I print x.author then it displays Redditor(user_name='abc') on the console so this is correct
author = re.findall(r'\'(.+?)\'', text)
print(author) #finds no match
为什么它不起作用的任何想法?