【问题标题】:How to get comments that contains curly brackets ({}) in Reddit with PRAW?如何使用 PRAW 在 Reddit 中获取包含大括号 ({}) 的评论?
【发布时间】:2021-07-13 17:02:49
【问题描述】:

我正在尝试为我正在开发的机器人检测使用 {} 的 cmets。我想要的是找到所有使用大括号的 cmets 并在这些括号之间获取字符串的脚本。因此,例如,如果评论说 {dog},我想访问“dog”。有什么建议吗?

【问题讨论】:

    标签: python praw


    【解决方案1】:

    使用这个正则表达式捕获大括号\{([^}]*)\} 内的文本怎么样? 然后你可以在你的 Python 代码中像这样使用它:

    import re
    
    regex = r"\{([^}]*)\}"
    test_str = "The {dog} is {barking} in the {yard}."
    matches = re.findall(regex, test_str, re.MULTILINE)
    
    print(matches)
    # ['dog', 'barking', 'yard']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      • 2020-05-23
      • 2020-10-17
      • 1970-01-01
      • 2020-11-23
      • 2021-09-25
      相关资源
      最近更新 更多