如何在Sublime Text中删除一组连续的n行中的换行符

huangapple go评论58阅读模式
英文:

How to remove newlines from a group of n-consecutive lines in sublime text

问题

我有一个文本文件,其中每一行都包含在单引号中的UUID,后面跟着一个逗号。这个文件的样本如下:

'527a34922f3472506d93f393c1dd5cac',
'7bdce3215c3007ccfb3449702234a2b4',
'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce',
'b038091601beb11c00d28d8ea277cecb',
'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48',
'10d3d4c4aa0f162d5ab3a403010c2202',
'1103abf37755c8477f0177478a0f91cd',
...

我正在使用Sublime Text 4,我需要将每3行分组并将它们合并成一行。所以,我期望的输出是:

'527a34922f3472506d93f393c1dd5cac', '7bdce3215c3007ccfb3449702234a2b4', 'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce', 'b038091601beb11c00d28d8ea277cecb', 'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48', '10d3d4c4aa0f162d5ab3a403010c2202', '1103abf37755c8477f0177478a0f91cd',
...

要如何实现呢?我可以使用这个命令选择每组3行:((.*\n){1, 3}),但无法对每个选择执行分组操作。

英文:

I've a text file where each line contains a uuid within single quote followed by a comma. A sample of this file would look like the following:

'527a34922f3472506d93f393c1dd5cac',
'7bdce3215c3007ccfb3449702234a2b4',
'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce',
'b038091601beb11c00d28d8ea277cecb',
'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48',
'10d3d4c4aa0f162d5ab3a403010c2202',
'1103abf37755c8477f0177478a0f91cd',
...

I'm using Sublime Text 4, and I need to group every 3 lines and pull them into a single line. So, the output I'm expecting is:

'527a34922f3472506d93f393c1dd5cac', '7bdce3215c3007ccfb3449702234a2b4', 'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce', 'b038091601beb11c00d28d8ea277cecb', 'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48', '10d3d4c4aa0f162d5ab3a403010c2202', '1103abf37755c8477f0177478a0f91cd',
...

How do I achieve that? I could select every group of 3 lines using this command: ((.*\n){1, 3}), but not able to perform the grouping on each selection.

答案1

得分: 2

Find:

(.*)\n(.*)\n(.*)\n

Replace:

  \n

Demo: https://regex101.com/r/lwmRCQ/1

英文:

You can capture the body of every line and match the trailing newline of each, do this for 3 lines and replace them with the three lines separated by spaces instead, and end with another newline:

Find:

(.*)\n(.*)\n(.*)\n

Replace:

  \n

Demo: https://regex101.com/r/lwmRCQ/1

huangapple
  • 本文由 发表于 2023年2月8日 14:55:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定