It is going to depend on exactly the patterns you want to match and the 
format of the changed result. Assuming the first subtitle block's subtitle 
text is a single line of text and the following subtitle block's subtitle 
text is a single word of all-lower-case characters (assuming that's what 
you want from your previous "Grep pattern needed" posting) followed by 
optional period punctuation mark, the following grep pattern will find that 
pattern and capture group parts for reassembly into the desired result:

^(\d+\s+\d{2}:\d{2}:\d{2},\d{3} --> 
)(\d{2}:\d{2}:\d{2},\d{3}\s+)(.+)(\s+\d+\s+\d{2}:\d{2}:\d{2},\d{3} --> 
)(\d{2}:\d{2}:\d{2},\d{3}\s+)((?-i)^[a-z]+[.]?[\W]*)$

The question is then what to you want the result to look like?

1) Just move the word from subtitle block 51 to the end of subtitle block 
50's subtitle text and leave everything else the same?

The replace pattern:
\1\2\3 \6\4\5

will produce as a result:

50

00:04:35,000 --> 00:04:42,840

However, what can happen is this can come at the cost of disregarding the 
larger whole.


51

00:04:42,840 --> 00:04:43,000

2) Change subtitle block 50's timecode end time to subtitle block 51's 
timecode end time along with moving subtitle block 51's single word 
subtitle text and completely remove what remains of the subtitle block 51 
entry?

The replace pattern:
\1\2\3 \6

will produce as a result:

50

00:04:35,000 --> 00:04:42,840

However, what can happen is this can come at the cost of disregarding the 
larger whole.

3) If you chose 2), the subtitle sequence numbers for the remaining 
subtitle blocks will no longer be sequential. Fixing the remaining subtitle 
blocks' subtitle sequence numbers so they are sequential can't be done 
using just grep find and replace patterns. You're going to need something 
beyond grep like a script to accomplish that and you might as well put all 
the finding and replacing in that script solution also to keep all the 
manipulation mechanics in one tidy package.

On Sunday, April 6, 2025 at 7:41:57 AM UTC-7 Otto Munters wrote:

> Example of a subtitle from which I want to move the single word in the 
> second timestamp to the end of the subtitle in the first timestamp.
> Is it possible to do that with a regex in BBedit? With Python or 
> Applescript, I can't work.
>
> 50
> 00:04:35,000 --> 00:04:42,840
> However, what can happen is this can come at the cost of disregarding the 
> larger
>
> 51
> 00:04:42,840 --> 00:04:43,000
> whole.
>
>
> Thank you for helping me!
> Otto
>

-- 
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 
"[email protected]" 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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/bbedit/cc1f5a82-d60e-4e8e-8417-c48e4c3805a1n%40googlegroups.com.

Reply via email to