简体   繁体   English

正则表达式 65 CPL 和无分词

[英]Regular Expression 65 CPL and No Word Breaks

I'm trying to perfect a regular expression to take paragraphs of text and arrange them with a 65 character per line limit, and specifically not to split any words.我正在尝试完善一个正则表达式来获取文本段落并将它们排列为每行 65 个字符的限制,特别是不要拆分任何单词。

I'm using Apache OpenOffice to Find and Replace.我正在使用 Apache OpenOffice 来查找和替换。
My Find expression:我的查找表达式:

(.{1,65}\s)

My Replace expression:我的替换表达式:

$1\n

Oddly the Find expression looks to do what I want on https://regex101.com/ but not in OpenOffice.奇怪的是 Find 表达式看起来可以在https://regex101.com/上执行我想要的操作,但在 OpenOffice 中却没有。
I've also tried in Notepad++ and that too doesn't produce the same result as regex101.com.我也在 Notepad++ 中尝试过,这也不会产生与 regex101.com 相同的结果。

In OpenOffice it seems to leave out the last word of each line.在 OpenOffice 中,它似乎遗漏了每一行的最后一个单词。
If I change my Find expression to (.{1,65}) that works, but then splits up words which I can't have.如果我将 Find 表达式更改为 (.{1,65}) 有效,但随后会拆分我无法拥有的单词。

Here's a chunk of sample text;这是一段示例文本;

Why do we use it?我们为什么用它?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.一个早已确立的事实是,读者在查看页面布局时会被页面的可读内容分散注意力。

I'm no expert in Regular Expressions so any assistance is greatly appreciated.我不是正则表达式方面的专家,因此非常感谢任何帮助。
Also open to other methods than OpenOffice Find and Replace.除了 OpenOffice 查找和替换之外,还可以使用其他方法。

Update-01:更新01:
So it seems to be that my Find expression only does what I need when there are soft line breaks (shift+enter) but not hard line breaks (enter).所以似乎我的 Find 表达式只在有软换行符(shift+enter)而不是硬换行符(enter)时才做我需要的事情。

If anyone knows how I can perfect the expression to behave the same for hard line breaks that'd be ideal.如果有人知道我如何完善表达式,使其对于硬换行符表现相同,那将是理想的。 Alternatively I'm looking into how to replace hard line breaks with soft line breaks.或者,我正在研究如何用软换行符替换硬换行符。 OpenOffice does actually support this but the other way around - if I Find \n and Replace with \n it will replace soft line breaks with hard line breaks. OpenOffice 确实支持这一点,但反过来 - 如果我 Find \n并用\n替换,它将用硬换行符替换软换行符。 I'm looking to do it the other way around though.我正在寻找相反的方式。

We ended up using NoteTab Light as the built-in Find and Replace treats the regular expressions and line breaks as we needed.我们最终使用了 NoteTab Light,因为内置的 Find and Replace 会根据需要处理正则表达式和换行符。

I wasn't unable to get AltSearch to work with these expressions, but honestly didn't spend too much time on it either.我不是无法让 AltSearch 使用这些表达式,但老实说,我也没有花太多时间在上面。

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

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