如何删除行中分隔符前的重复用户名?

如何删除行中分隔符前的重复用户名?

我想删除分隔符 : 之前的行中重复的用户名并仅保留这些用户名的第一行。

线条示例:

zzzz:000000zl
zzzz:000000zl!
zzzz:000000zl1
zzzz:000000zl123
zzzz:000000zl69
zzzz:000000zl?
AdSFF12:Sample198445
AdSFF12:Sample198445!
AdSFF12:Sample198445#
AdSFF12:Sample198445$
AdSFF12:Sample1984456
TestOf13:Smpletest1211
TestOf13:Smpletest1211!
TestOf13:Smpletest1211#
TestOf13:Smpletest1211$
TestOf13:Smpletest12112
TestOf13:Smpletest561
TestOf13:Smpletest561!
TestOf13:Smpletest561#
TestOf13:Smpletest561$
TestOf13:Smpletest5612
TestOf13:SmpletestZ2
TestOf13:SmpletestZ2!
TestOf13:SmpletestZ2#
TestOf13:SmpletestZ2$
TestOf13:SmpletestZ23
TestOf13:Smpletestz3qwe
TestOf13:Smpletestz3qwe!
TestOf13:Smpletestz3qwe1
TestOf13:Smpletestz3qwe123
TestOf13:Smpletestz3qwe69
TestOf13:Smpletestz3qwe?

所需结果:

zzzz:000000zl
AdSFF12:Sample198445
TestOf13:Smpletest1211

非常感谢您的帮助,提前谢谢您<3。

答案1

  • Ctrl+H
  • 找什么:^((.*?:).+\R)(\2.+\R)+
  • 用。。。来代替:$1
  • 查看 环绕
  • 查看 正则表达式
  • 取消选中 . matches newline
  • Replace all

解释:

^       # beginning of line
    (       # start group 1
        (       # start group 2
            .*?     # 0 or more any character but newline, not greedy
            :       # a colon
        )       # end group 2
        .+      # 0 or more any character but newline
        \R      # any kind of linebreak (i.e. \r, \n, \r\n)
    )       # end group 1
    (       # group 3, you can use (?: for non capture group
        \2      # back reference to group 2 (i.e. the part before the colon)
        .+      # 0 or more any character but newline
        \R      # any kind of linebreak (i.e. \r, \n, \r\n)
    )+      # end of group 3, may appear 0 or more times

替代品:

$1          # content of group 1, the value of the first line

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述

相关内容