M
M
Maximych892021-09-29 14:46:17
PHP
Maximych89, 2021-09-29 14:46:17

How to insert a new line after a different number of words?

Hello.

Help, please, with a regular expression or a script.

There are 10k files with texts in one line.
It is necessary to look for a "point with a space" in each file every 25 words / 70 words / 40 words / 30 words / 100 words and make a paragraph. That is, we go through 25 words and look for "." If not, we look for the nearest occurrence of "." and make a paragraph. Then after 70 words we look for the nearest occurrence of "." and make a paragraph. And so on, and then again.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DENIS Kokorev, 2021-09-29
@Maximych89

https://regex101.com/r/7VTUeP/1/ - hold on. Then you will understand. Only here not words but letters. Count yourself on average how many letters in 25 words / 70 words / 40 words / 30 words / 100 word(s)
Tex, stop, hurry up. Not suitable. Let's think right now.
https://regex101.com/r/KkDZnt/1 - here it is, finalized. More or less like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question