英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论