【问题标题】:Delete lines that only contain specific words删除仅包含特定单词的行
【发布时间】:2021-03-19 12:41:24
【问题描述】:

我有一个大文本文件(来自 discord 的消息日志,准备在 ML 中使用) 可以有这样的内容:

username1
@username2, whats up
username2
username1, im good, and username3 is also doing well

(唯一用户名的数量相对较少,因此我可以轻松手动查找替换它们,并且名称更真实且其中没有数字) 问题是,我需要删除这些行,其中只有username,仅此而已。 所以这里是

@username2, whats up
username1, im good, and username3 is also doing well

blackground : 我使用的库将每一行视为单独的文本,因此如果未删除,它会生成用户名,而不是消息,因为标题名称的剪切数量

更好的例子,取自实际文件:

adyos
He reacted to invitation
adyos
And by  the way, basic nightbot commands are up
adyos
And...
Captain Lea Skywalker
MEE6 is better, adyos ????

例外:

He reacted to invitation
And by  the way, basic nightbot commands are up
And...
MEE6 is better, adyos ????

【问题讨论】:

  • 第二个示例的预期输出是什么?
  • 如何区分用户名和其他文字?
  • Tim Biegeleisen : 编辑后发布 Toto : 我会手动查找和补充每个名字,最多有 10 个

标签: replace notepad++ line


【解决方案1】:

如果我很了解您的需求并且您的用户名数量很少,您可以使用以下方法:

  • Ctrl+H
  • 查找内容:^(?:adyos|user2)$\R?
  • 替换为:LEAV EMPTY
  • 检查 匹配大小写
  • 检查 环绕
  • CHECK 正则表达式
  • 全部替换

说明:

^           # beginning of line
    (?:         # non capture group
        adyos       # username 1
      |           # OR
        user2       # username 2
    )           # end group, you can add all your usernames separated by a pipe |
$           # end of line
\R?         # optional linebreak

屏幕截图(之前):

截图(之后):

【讨论】:

  • 谢谢!我设法让一些东西工作,但它很糟糕,这好多了。这对我来说是一个矫枉过正的答案,非常感谢!
  • @TabletkaTabletkova:不客气,很高兴它有帮助。随意将答案标记为已接受,How to accept an answer
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-18
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 2020-09-23
相关资源
最近更新 更多