REGEX:将一个段落中的所有单词放在一行上

REGEX:将一个段落中的所有单词放在一行上

如下所示,所有释义中的每一行都是未完成的。段落中每行开头的单词不是上一行的延续。我感兴趣的是将释义中的所有行连接起来,而没有任何单词中断。

When the water rises up to F, the piece at A will be visible; when it
reaches G, both A and B will be visible; and when it comes up to H,
all three pieces will be visible.


_Artificial Earthquake and Volcano._

Grind an equal quantity of fresh iron filings with pure sulphur, till
the whole be reduced to a fine powder. Be careful not to let any wet
come near it. Then bury about thirty pounds of it a foot deep in the
earth, and in about six or eight hours the ground will heave and
swell, and shortly after send forth smoke and flames like a burning
mountain. If the earth is raised in a conical shape, it will be no bad
miniature resemblance of one of the burning mountains.


_Artificial Illuminations._

A very pleasing exhibition may be made with very little trouble or
expense, in the following manner: Provide a box, which you fit up with
architectural designs cut out on pasteboard; prick small holes in
those parts of the building where you wish the illuminations to
appear, observing, that in proportion to the perspective, the holes
are to be made smaller; and on the near objects the holes are to be
made larger. Behind these designs thus perforated, you fix a lamp or
candle, but in such a manner that the reflection of the light shall
only shine through the holes; then placing a light of just sufficient
brilliance to show the design of the buildings before it, and making a
hole for the sight at the front end of the box, you will have a very
tolerable representation of illuminated buildings.

输出

When the water rises up to F, the piece at A will be visible; when it reaches G, both A and B will be visible; and when it comes up to H, all three pieces will be visible.


_Artificial Earthquake and Volcano._

Grind an equal quantity of fresh iron filings with pure sulphur, till the whole be reduced to a fine powder. Be careful not to let any wet come near it. Then bury about thirty pounds of it a foot deep in the earth, and in about six or eight hours the ground will heave and swell, and shortly after send forth smoke and flames like a burning mountain. If the earth is raised in a conical shape, it will be no bad miniature resemblance of one of the burning mountains.


_Artificial Illuminations._

A very pleasing exhibition may be made with very little trouble or expense, in the following manner: Provide a box, which you fit up with architectural designs cut out on pasteboard; prick small holes in those parts of the building where you wish the illuminations to appear, observing, that in proportion to the perspective, the holes are to be made smaller; and on the near objects the holes are to be made larger. Behind these designs thus perforated, you fix a lamp or candle, but in such a manner that the reflection of the light shall only shine through the holes; then placing a light of just sufficient brilliance to show the design of the buildings before it, and making a hole for the sight at the front end of the box, you will have a very tolerable representation of illuminated buildings.

我的正则表达式效果不太好:

寻找:^(.*?)$(\K.*)\r

替换为:\2

或(更好的一个)

寻找:^(.*?)$(\R)

替换为:\1

答案1

使用 Notepad++,它可能与 SublimeText 兼容。


  • Ctrl+H
  • 找什么:\R+_.+_\R+(*SKIP)(*FAIL)|\R
  • 替换为: # 一个空格
  • 打钩 环绕
  • 选择 正则表达式
  • 取消勾选 . matches newline
  • Replace all

解释:

\R+         # 1 or more any kind of linebreak
_.+_        # 1 or more any character surounded by underscores
\R+         # 1 or more any kind of linebreak
(*SKIP)     # skip this match
(*FAIL)     # and considere it failed
|           # OR
\R          # any kind of linebreak

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述

答案2

一个非常简单且有用的正则表达式公式:

寻找: ([^\r\n])\R([^\r\n])

替换为: \1 \2

答案3

  • Ctrl+H
  • 找什么:\R(?=.)
  • 用。。。来代替:(leave empty)
  • 查看 环绕
  • 查看 正则表达式
  • 取消选中 . matches newline
  • Replace all

相关内容