【问题标题】:Cleanning texts with Notepad++使用 Notepad++ 清理文本
【发布时间】:2012-11-30 12:18:55
【问题描述】:

我有一个推文文档,它包含这样的行:

RichardJ0nes -- Should I upgrade to an iPhone 5? Decisions, decisions!
AnthonyMOliva -- @AnthonyMOliva AT&T offering iPhone 5 refurbished starting at $99: Two months after making its debut, refur... http://t.co/IsPDzIrD #BBC
mittrashi -- RT @timesofindia: Apple iPhone 5S, iPad 5 already in the works? - The Times of India http://t.co/s782BHp5

我想清理这个文档。 首先我想清理用户名(例如:RichardJ0nes -- 或@AnthonyMOliva),其次我想清理链接(例如http://t.co/s782BHp5)。

应该是这样的:

Should I upgrade to an iPhone 5? Decisions, decisions!
AT&T offering iPhone 5 refurbished starting at $99: Two months after making its debut, refur... 
Apple iPhone 5S, iPad 5 already in the works? - The Times of India

我尝试在记事本++上使用正则表达式做一些事情,但我无法清理文本

我尝试删除第一个用户名
找到.*\(--\) 替换:\1

但它不适用于记事本++。我该怎么做,请给我一个想法?

【问题讨论】:

    标签: java regex text notepad++


    【解决方案1】:

    搜索(^\S+\s--|\bhttps?://\S+|(?:^|(?<=\s))[@#]\S+)\s?并将其替换为空字符串。

    【讨论】:

    • 也许在 [@#] 之前添加 (?:RT )? 也可以匹配。
    • @garyh - 我相信 OP 想要保留这一点,即使他/她的问题也没有显示。否则,关于搜索/替换规则的问题不清楚......
    • 我同意,OP 不清楚,因为他们没有明确声明删除RT,但它没有出现在清理后的文本中。只是增加价值!
    【解决方案2】:

    在记事本++中按ctrl+f,转到替换选项卡并在底部选择搜索模式中的正则表达式,然后执行以下操作

    1. 搜索:.* -- (.*)$ 并全部替换为\1
    2. 搜索:@[^ ]* 并全部替换为空(将替换输入留空)
    3. 搜索:http[^ ]* 并全部替换为空(将替换输入留空)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      相关资源
      最近更新 更多