替换为特定的经文

Replace for specific verse

我昨天确实花了几个小时试图替换 notepad++ 中的换行符。

我有类似的东西:

"1:30 And to every beast of the earth, and to every fowl of the air,
and to every thing that creepeth upon the earth, wherein there is
life, I have given every green herb for meat: and it was so. 

1:31 And God saw every thing that he had made, and, behold, it was
very good. And the evening and the morning were the sixth day. 

2:1 Thus the heavens and the earth were finished, and all the host of
them. 

2:2 And on the seventh day God ended his work which he had made; and
he rested on the seventh day from all his work which he had made."

令人惊讶的是,在 notepad++ 中,Regex 无法识别 /n/n。当我 运行 搜索时,它一无所获,尽管每节经文的末尾都有一个明显的双换行符。非常沮丧。解决方案是找到 \r\n\r.

但这会在每一节的结尾添加一个中断。如何使用正则表达式在一章的每一节最后一节的末尾添加一个中断?冒号前的第一个数字是章节。

我应该找到像 [0-9]:[0-9]+[A-Z] 这样的东西……对吗?


编辑,我希望从:

1:30 And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat: and it was so.

1:31 And God saw every thing that he had made, and, behold, it was very good. And the evening and the morning were the sixth day.

2:1 Thus the heavens and the earth were finished, and all the host of them.

2:2 And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made

类似于:

1:30 And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat: and it was so.

1:31 And God saw every thing that he had made, and, behold, it was very good. And the evening and the morning were the sixth day.

    <br>

2:1 Thus the heavens and the earth were finished, and all the host of them.

2:2 And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made

另一个例子是:

2:23 And Adam said, This is now bone of my bones, and flesh of my
    flesh: she shall be called Woman, because she was taken out of Man.

2:24 Therefore shall a man leave his father and his mother, and shall
    cleave unto his wife: and they shall be one flesh.

2:25 And they were both naked, the man and his wife, and were not
    ashamed.

3:1 Now the serpent was more subtil than any beast of the field which
    the LORD God had made. And he said unto the woman, Yea, hath God said,
    Ye shall not eat of every tree of the garden?  3:2 And the woman said
    unto the serpent, We may eat of the fruit of the trees of the garden:

3:3 But of the fruit of the tree which is in the midst of the garden,
    God hath said, Ye shall not eat of it, neither shall ye touch it, lest
    ye die.

类似于:

    2:23 And Adam said, This is now bone of my bones, and flesh of my
    flesh: she shall be called Woman, because she was taken out of Man.

    2:24 Therefore shall a man leave his father and his mother, and shall
    cleave unto his wife: and they shall be one flesh.

    2:25 And they were both naked, the man and his wife, and were not
    ashamed.

    <br>

    3:1 Now the serpent was more subtil than any beast of the field which
    the LORD God had made. And he said unto the woman, Yea, hath God said,
    Ye shall not eat of every tree of the garden?  3:2 And the woman said
    unto the serpent, We may eat of the fruit of the trees of the garden:

    3:3 But of the fruit of the tree which is in the midst of the garden,
    God hath said, Ye shall not eat of it, neither shall ye touch it, lest
    ye die.

我做了这个并在 Notepad++ 中测试了它。这是否满足您的需求?如果您的输入文本文件中没有双换行符,请将下面的 \r\n\r\n 换成 \r\n.

(\d+)(:\d+\s.+\r\n\r\n)((:.*\r\n\r\n)+)

替换为:

\r\n

测试字符串:

1:30 And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat: and it was so.

1:31 And God saw every thing that he had made, and, behold, it was very good. And the evening and the morning were the sixth day.

1:32 Lorem ipsum

2:1 Thus the heavens and the earth were finished, and all the host of them.

2:2 And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.

编辑(考虑 within-verse 个换行符):

(\d+)(:\d+\s(.|(\r\n[^\r\n]))+\r\n\r\n(:(.|(\r\n[^\r\n]))*\r\n\r\n)+)

替换为:

\r\n

Regex:

(?<verse>(?<block>^(?<num>\d+):\d+\s(?<txt>(?s).*?)(?<end>\n{2})(?!(?P=num)))+?)

工作原理:

命名捕获组:

  • verse - 我们希望在目标之后添加一个 line-break。
  • block - 节的单个子元素,从行首开始 ^
  • num - 当前节数。
  • txt - 文字内容。
  • end - 块结束,使用两个连续的 line-breaks

*为了便于解释,捕获了一些命名组。

机制:

  • verse 将包含尽可能多的 blocks +? 直到到达具有不同 num 的块, 使用负 look-ahead ?! 定位在 end 之后,不应该 匹配组 num.
  • 的最后一个值
  • txt 使用局部修饰符 s (single-line) 在使用 .
  • 时包含换行符

用自身+<br>替换(verse)

\n${verse}<br>\n\n