Как в списке удалить весь текст выше 3-рёх подряд строк заканчивающихся на знаки преп
Вложений: 1
Есть переменная [[LIST_WITH_FILE_CONTENT]] в ней много строчек.
Подскажите, как с помощью JS удалить в нём все строки что выше 3-рёх подряд идущих строк. В конце этих 3-рёх строк должны стоять символы из списка [[SYMBOLS]] . В списке [[SYMBOLS]] находятся знаки препинания: . , ! ? " ' : ” “ Пример [[LIST_WITH_FILE_CONTENT]] : Or to take arms against a sea of troubles? And by opposing end them. To die—to sleep No more; and by a sleep to say we end. The heart-ache and the thousand natural shocks That flesh is heir to: ’tis a consummation! Devoutly to be wish’d. To die, to sleep; To sleep, perchance to dream—ay, there’s the rub: For in that sleep of death what dreams may come Borne on the bier6 with white and bristly beard: Then of thy beauty do I question make Должно остаться так (выделил красной рамкой): см скриншот во вложении |
mik888em,
:-? <script> let text = `Or to take arms against a sea of troubles? And by opposing end them. To die—to sleep No more; and by a sleep to say we end. The heart-ache and the thousand natural shocks That flesh is heir to: ’tis a consummation! Devoutly to be wish’d. To die, to sleep; To sleep, perchance to dream—ay, there’s the rub: For in that sleep of death what dreams may come Borne on the bier6 with white and bristly beard: Then of thy beauty do I question make `; let redo = new Set(); let regStr = /(^[\s\S]+\n)(?=(.*?[.,!?"':;”“]\n){3})/mg; function replace(a, b, c) { return ''; } text = text.replace(regStr, replace); document.write(`<pre>${text}</pre>`) </script> |
Предложу такой вариант...
<textarea id='txt'>Or to take arms against a sea of troubles? And by opposing end them. To die—to sleep No more; and by a sleep to say we end. The heart-ache and the thousand natural shocks That flesh is heir to: ’tis a consummation! Devoutly to be wish’d. To die, to sleep; To sleep, perchance to dream—ay, there’s the rub: For in that sleep of death what dreams may come Borne on the bier6 with white and bristly beard: Then of thy beauty do I question make</textarea> <script> let txt = document.querySelector('#txt').value const re = /([^\n]*[!:;]\n){3}/ const n = txt.search(re) txt = txt.substring(n, txt.length) alert(txt) </script> |
ksa,
:) |
рони, я не поспеваю за тобой. :write:
|
Часовой пояс GMT +3, время: 06:23. |