正则表达式:用单引号

时间:2016-02-18 20:07:13

标签: python regex

我正在尝试解析用单引号括起来的字符串。

  

对于输入: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

为什么它不起作用的任何想法?

0 个答案:

没有答案
相关问题