如何编写 RegEx 以插入行长度超过 30 个字符的换行符 [英] How to write RegEx for inserting line break for line length more than 30 characters
本文介绍了如何编写 RegEx 以插入行长度超过 30 个字符的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用文本编辑器,它让我可以使用正则表达式来查找/替换文本.我有一个大文本文件,想在超过 30 个字符的行中插入一个新行.我希望该行在第 30 个字符后断开,并且单词或短语是否断开都没有关系.
I am using a text editor which lets me use regular expressions to find/replace text. I have a large text file and want to insert a new line in lines which are more than 30 characters. I want the line to break after the 30th character and it doesn't matter if a word or phrase breaks or not.
原文:
Hi this is a sample text.
this is a line.
This is a very very very very very long line.
This is a regular line.
....
修改后的文字:
Hi this is a sample text.
this is a line.
This is one very very very ver
y very long line.
This is a regular line.
....
如何编写正则表达式:
- 查找超过 30 个字符的行.
- 在长度超过 30 个字符的行中的第 30 个字符之后插入一个新行.
推荐答案
查找内容:
^(.{30})
替换为:
\1\n
这篇关于如何编写 RegEx 以插入行长度超过 30 个字符的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文