omunters@xs4all.nl

107 views
Skip to first unread message

Otto Munters

unread,
Jul 29, 2024, 6:11:55 AM7/29/24
to BBEdit Talk
Hi BB friends

How can I find text blocks consisting of 5 lines?
Example:
line 1
line 2
line 3
line 4

line 5
line 6
line 7
line 8
line 9

I then want to find the second block of text.

thanks for your help!
Otto


Ulrich Kapp

unread,
Jul 29, 2024, 8:33:49 AM7/29/24
to BBEdit Talk
Hi Otto,

I hope my last hint did help you.

Here's the one for the question above:

Use the search pattern (.{1,}\n){5with Regex activated.

Cheers!

flet...@cumuli.com

unread,
Jul 29, 2024, 9:03:08 AM7/29/24
to bbe...@googlegroups.com
You can use the repetition modifier on a parentheses group to find a pattern that repeats so many times.

This will find five repetitions of a line that starts with an alphanumeric character.

(\w.*?\n){5}

You can use non-grouping parentheses (:? ... ) if you need to do search/replaces with this.

[fletcher]

--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3bdd6c14-8220-4159-9e0c-7b48aedfa74an%40googlegroups.com.

Otto Munters

unread,
Jul 29, 2024, 9:08:44 AM7/29/24
to BBEdit Talk
Hi Ulrich

This helps to find the sentences I want to improve.
It's about subtitles, which I want to get on 2 lines.
Also, is there a Greb that allows me to paste the word(s) on the 3rd line of text behind the second line of text?
This is an example:

184
00:10:42,150 --> 00:10:47,930
But the content, which it was
always having its existence in,
which

185
00:10:47,930 --> 00:10:51,970
never had its existence apart
from, which has its existence in
 now,

should be:
184
00:10:42,150 --> 00:10:47,930
But the content, which it was
always having its existence in,
which

185
00:10:47,930 --> 00:10:51,970
never had its existence apart
from, which has its existence in now,

Thanks in advance!
Best regards, Otto
Op maandag 29 juli 2024 om 14:33:49 UTC+2 schreef Ulrich Kapp:

Neil Faiman

unread,
Jul 29, 2024, 3:50:54 PM7/29/24
to BBEdit Talk Mailing List
Two comments about the suggested pattern

(.{1,}\n){5}

First, the sub-pattern “.{1,}” could also be written as “.+”. The + suffix means exactly the same thing as the {1,} suffix, that is, “one or more occurrences of the preceding pattern”. It is a personal choice which one you prefer. (I believe that the specific suffixes + (1 or more), * (0 or more), and ? (0 or 1) were part of the GREP pattern language before the more general {m,n} (at least m but no more than n).)

Second, if you have more than five consecutive non-blank lines, the suggested pattern will match the first five. If you only want to match groups of exactly five non-blank lines, I would suggest something like this:

(?<=\n\n|\A)(.{1,}\n){5}$


The (?<=\n\n|\A) prefix says that the following pattern will only match if it is preceded by (the ?<= operator) either a blank line (the \n\n — i.e., two end-of-lines with nothing between) or (the.| operator) the beginning of the document (the \A). Therefore, five consecutive non-blank lines will not match the pattern if they are preceded by another non-blank line.

Similarly, the $ suffix says that the pattern must be followed by either another end-of-line (i.e., an empty line) or the end of the document. Therefore, five consecutive non-blank lines will not match the pattern if they are followed by another non-blank line.


Ulrich Kapp

unread,
Jul 30, 2024, 2:24:53 AM7/30/24
to BBEdit Talk
Hi Otto,

I suggest "(^[\d]{3}$)\n(^[\d]{2}.*[\d]{3}$)\n(^.*$)\n(^.*$)\n(^.*$)" as search pattern
and "\1\n\2\n\3\n\4 \5" as replacement pattern.

But with no guarantee…

It would be best to play around in the pattern playground with a copy of the original data, I think.

Have a nice day, Ulrich

p.s.: The rest of the week I'm  offline. :)

Otto Munters

unread,
Aug 5, 2024, 10:52:58 AM8/5/24
to BBEdit Talk
Thanks Ulrich!


Op dinsdag 30 juli 2024 om 08:24:53 UTC+2 schreef Ulrich Kapp:
Reply all
Reply to author
Forward
0 new messages