【问题标题】:Remove pattern from social media specific string从社交媒体特定字符串中删除模式
【发布时间】:2020-07-07 09:21:28
【问题描述】:

我需要清理来自社交媒体的一些字符串。字符串中不时出现以下模式:

Pattern = 'Quote:\nOriginally Posted by username_xy  View Post' 

当匹配发生时检查字符串以删除此模式的最佳方法是什么?

(模式中的用户名可能不同)

【问题讨论】:

  • 这个字符串的哪一部分需要清理?
  • 对不起,我没有提到这是一个字符串的sn-p。这种模式通常可以出现在字符串中的任何位置,应该被删除。

标签: python regex string


【解决方案1】:

看看这是否适合你

import re

regex = r"Quote:\sOriginally[\s]+Posted[\s]+by[\s]+[\w]+[\s]+View[\s]+Post"
re.sub(regex, '', 'Quote:\nOriginally Posted by username_xy  View Post' )

【讨论】:

    猜你喜欢
    • 2017-02-26
    • 2020-10-08
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    相关资源
    最近更新 更多