I literally spent hours yesterday trying to replace line breaks in notepad .
I had something like:
"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."
Surprisingly, in notepad , Regex doesn't recognize /n/n. When I run the search, it found nothing, even though there is clearly a double line break at the end of each verse. Was very fustrated. The solution was to find \r\n\r.
But that adds a break at the end of every verse. How can I add a break at the end of every last verse in a chapter using Regex? The first number before the colon is the chapter.
I should find something like [0-9]:[0-9] [A-Z].... right?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Edit, that is I wish to go from:
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
to something like:
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
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Another example is:
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.
to something like:
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.
CodePudding user response:
I made this and tested it in Notepad . Does this fulfill your needs? If there aren't double line breaks in your input text file, swap out the \r\n\r\n in the below for just \r\n.
(\d )(:\d \s. \r\n\r\n)((\1:.*\r\n\r\n) )
Replace with:
\1\2\3\r\n
Test strings:
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.
Edit (to account for within-verse newline characters):
(\d )(:\d \s(.|(\r\n[^\r\n])) \r\n\r\n(\1:(.|(\r\n[^\r\n]))*\r\n\r\n) )
Replace with:
\1\2\r\n
CodePudding user response:
(?<verse>(?<block>^(?<num>\d ):\d \s(?<txt>(?s).*?)(?<end>\n{2})(?!(?P=num))) ?)
How it works:
Named capture groups:
verse
- target we wish to add a line-break after.block
- single sub element of a verse, starts at the beginning of line^
num
- current verse number.txt
- text content.end
- end of block, uses two consecutive line-breaks
*some named groups captured just for the ease of explaining.
Mechanism:
verse
will contain as muchblock
s as possible?
until it reaches a block with differentnum
, using negative look-ahead?!
positioned afterend
and should not match the last value of groupnum
.txt
use local modifiers
(single-line) to include line breaks when using.
Replace (verse
with itself <br>
)
\n${verse}<br>\n\n