【问题标题】:How to remove all the characters on a line before a specified character如何删除指定字符前一行的所有字符
【发布时间】:2021-08-17 10:20:45
【问题描述】:

你好,我得到了这种格式的东西,我需要在第一个“:”之前删除所有内容

之前:

1:2:3
a:b:c

之后:

2:3
b:c

我试过这个^.+[:],但是在这个命令之后我没有得到2:3 b:c,而只有3c,这个命令删除了第二个“:

如果我们最终得到这个,我想替换它们。

之前:

2:3
b:c

之后:

3:2
c:b

【问题讨论】:

  • 我想不出一种方法来告诉 Notepad++ 每行只执行一次该过程。问题是即使您修改正则表达式以一次删除一个冒号,它也会一直重复到最后一个冒号。 Java/Python 解决方案是否可行?

标签: replace notepad++ delete-row


【解决方案1】:

不完全了解您的需求,但我猜您想删除第一列并交换其他 2。

这是一步完成的方法:

  • Ctrl+H
  • 查找内容:^.+?:([^:]+):(.+)$
  • 替换为:$2:$1
  • 检查 匹配大小写
  • 检查 环绕
  • CHECK 正则表达式
  • 取消选中 . matches newline
  • 全部替换

说明:

^           # beginning of line
    .+?         # 1 or more any character but newline, not greedy
    :           # colon
    ([^:]+)     # group 1, 1 or more any character that is not a colon
    :           # colon
    (.+)        # group 2, 1 or more any character but newline
$           # end of line

替换:

$2          # content of group 2, 3rd column
:           # colon
$1          # content of group 1, 2nd column

屏幕截图(之前):

截图(之后):

【讨论】:

  • 我不确定他是否想交换另外两个。但这个问题自相矛盾,有两个不同的“之后”
猜你喜欢
  • 1970-01-01
  • 2017-04-16
  • 2015-09-05
  • 2015-01-26
  • 1970-01-01
  • 1970-01-01
  • 2016-11-08
  • 2016-07-06
  • 2011-07-16
相关资源
最近更新 更多