Notepad++ 中字符行的条件合并

Notepad++ 中字符行的条件合并

我在 notepad++ 中有一个这样的问题;

123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

我希望将上述问题放在一行中。所有问题都将以答案选项“a”开头。由于问题超过 100 个,因此很难在每个问题上都应用 CTRL+J。

需要您的建议。

答案1

您可以使用以下表达方式:

  • 找什么:\r\n(?!(\d{3}|[a-z])\.? )
    (取决于您的操作系统,您可能需要删除\r
  • 替换为:“”(没有什么)
  • 确保选中“正则表达式”

无论字母后面是否有点(“c.”),此方法都有效(“a”)。

测试在这里:https://regex101.com/r/4WKuA9/2

在此处输入图片描述

答案2

  • Ctrl+H
  • 找什么:(?:^\d+\.|\G).+\K\R(?!^[a-z]\.?\h)
  • 用。。。来代替:A SPACE
  • 取消勾选匹配大小写
  • 检查环绕
  • 检查正则表达式
  • 取消选中. matches newline
  • Replace all

解释:

(?:             # start non capture group
  ^             # beginning of line
    \d+         # 1 or more digits
    \.          # a dot
  |             # OR
    \G          # restart from last match position
)               # end group
.+              # 1 or more any character but newline
\K              # forget all we have seen until this position
\R              # any kind of linebreak (i.e. \r, \n, \r\n)
(?!             # neagative lookahead, zero-length assertion that makes sure we haven't after: 
  ^             # beginning of line
    [a-z]       # a small letter
    \.?         # an optional dot
    \h          # 1 horizontal space
)

鉴于:

123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land
123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

给定示例的结果:

123. The airplane will not land in time if weather is not clear due to rain and storm. Are you acceptable to re turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land
123. The airplane will not land in time if weather is not clear due to rain and storm. Are you acceptable to re turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

屏幕截图(之前):

在此处输入图片描述

屏幕截图(之后):

在此处输入图片描述

相关内容