简体   繁体   English

如何使用记事本++对文本行进行分组

[英]How to group lines of text using Notepad++

I find Notepad++ regex to be very different from regex in Microsoft Word. 我发现Notepad ++正则表达式与Microsoft Word中的正则表达式非常不同。 I was wondering how I can group several lines of text using Notepad++. 我想知道如何使用Notepad ++将几行文本分组。 I have a text file with 100+ URLs. 我有一个包含100多个网址的文本文件。 They are written one URL address per line. 它们每行被写入一个URL地址。 I would like to group all of them by tens by removing the carriage returns from every first to 9th line, but retaining the carriage return on every 10th line and adding another carriage return thereafter. 我想通过从第一行到第9行删除回车符,但在每10行保留回车符并在其后添加另一个回车符,将所有这些按十个分组。 For example: 例如:

I want this: 我要这个:

http://website1.com
http://website2.com
http://website3.com
http://website4.com
http://website5.com
http://website6.com
http://website7.com
http://website8.com
http://website9.com
http://website10.com
http://website11.com
http://website12.com
http://website13.com
http://website14.com
http://website15.com
http://website16.com
http://website17.com
http://website18.com
http://website19.com
http://website20.com
http://website21.com
http://website22.com
http://website23.com
http://website24.com
http://website25.com
http://website26.com
http://website27.com
http://website28.com
http://website29.com
http://website30.com

to look like: 看起来像:

http://website1.comhttp://website2.comhttp://website3.comhttp://website4.comhttp://website5.comhttp://website6.comhttp://website7.comhttp://website8.comhttp://website9.comhttp://website10.com

http://website11.comhttp://website12.comhttp://website13.comhttp://website14.comhttp://website15.comhttp://website16.comhttp://website17.comhttp://website18.comhttp://website19.comhttp://website20.com

http://website21.comhttp://website22.comhttp://website23.comhttp://website24.comhttp://website25.comhttp://website26.comhttp://website27.comhttp://website28.comhttp://website29.comhttp://website30.com

Any help would be appreciated! 任何帮助,将不胜感激!

Ok, I have found a way: 好的,我找到了一种方法:

There is a such possibility, but only with 6 entries in a row (longest regex is not parsed by the Notepad++). 有这种可能,但是连续只有6个条目(最长的正则表达式不会由Notepad ++解析)。

1)So, open the file and remove from it all newlines characters, so the text will be a long-long line. 1)因此,打开文件并从其中删除所有换行符,这样文本将是一长行。

2)Open replace dialog, insert in the "Find what" field the next : 2)打开替换对话框,在“查找内容”字段中插入下一个:

(http://[^\\:]*\\.comhttp://[^\\:]*\\.comhttp://[^\\:]*\\.comhttp://[^\\:]*\\.comhttp://[^\\:]*\\.comhttp://[^\\:]*\\.com)

and in the "Replace With" the next: 然后在“替换为”中:

\1\r\n

Put the cursor at the first position in the text and press "Replace all" 将光标放在文本的第一个位置,然后按“全部替换”

So, the regex contains this (http://[^\\:]*\\.com){6} (the regex is repeated 6 times). 因此,正则表达式包含此(http://[^\\:]*\\.com){6} (正则表达式重复了6次)。 If you work with Unix and you need unix-type new line style, replace this : \\1\\r\\n with this \\1\\n 如果您使用的是Unix,并且需要使用Unix类型的换行符,请使用以下\\1\\n替换: \\1\\r\\n \\1\\n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM