如何在记事本 ++ 中重新排列文本,例如如何从“A”:“B”到“B”:“A”,但对于多个唯一行?

How do I rearrange text in notepad++ for example how do I go from: “A”:”B” to “B”:”A” but for multiple unique lines?

所以基本上我正在尝试使用记事本 ++ 大规模反转我的文本,70,000 行

我正试图从中得到:

“A”:“B”

对此:

“B”:“A”

但是,并非所有行都包含相同数量的字符。实际上,我只想将冒号左侧的所有内容倒置到右侧,以及冒号右侧到左侧的所有内容。我该怎么做? 谢谢!

  • Ctrl+H
  • 查找内容:^(.+?):(.+)$
  • 替换为::
  • 检查 环绕
  • 检查 正则表达式
  • 取消选中 . matches newline
  • 全部替换

解释:

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

替换:

      # content of group 2
:       # colon
      # content of group 1

屏幕截图(之前):

截图(后):

一种方法是通过 Notepad++ 中的宏。宏基本上是一种自动执行任务的方法,它通过记录一行的击键然后为整个文档播放录制的宏。以上面的例子为例,假设我们想要

“A”:”B”

然后把它变成这样:

“B”:”A”

这是一个循序渐进的宏的样子:

1. Verify your cursor is at the beginning of the document.
2. Start recording your Macro (Macro -> Start Recording).
3. Ctrl-f the colon (:).
4. Press the backspace key to delete the colon character. We will re-add that colon back in later.
5. Click and hold the Shift button, then press the home button. This will select all the characters to the left side of the colon.
6. Press Ctrl-x to cut the selection
7. Press the end button to take you to the end of the current line.
8. Type in your colon once again
9. Press Ctrl-v to paste your selection.
10. Stop recording your Macro.
11. Replay your Macro until the document's end.

这将有效删除冒号,将冒号前的每个字符都取出并剪切,然后在行尾再次添加冒号并将剪切掉的字符添加到冒号后,有效地切换字符的位置.

还有其他方法可以使用正则表达式或其他方法来执行此操作,但这是我首先想到的。

要了解有关宏的更多信息:https://npp-user-manual.org/docs/macros/