How to remove timing string?

106 views
Skip to first unread message

Otto Munters

unread,
May 30, 2023, 8:28:48 AM5/30/23
to BBEdit Talk
Hello, I am a new BBEdit user and want to remove all timings from a srt file to use it as a text document. It looks like this now:
1
00:00:33,360 --> 00:00:45,060
Welcome. Lovely to see you all. We
should take our time to introduce

2
00:00:46,560 --> 00:00:52,380
the rules. Just like you have ashram
rules, we have rules for self inquiry.  

3
00:00:55,200 --> 00:01:01,080
Vedanta is an ancient tradition,
science of self inquiry

All the first two lines of each paragraph (page number and timing) I want to remove. I also want to remove the blank lines so that one large block of text remains.

Can anyone help me with the code I can use as a Grep?
Thanks in advance!

Rod Buchanan

unread,
May 30, 2023, 10:08:57 AM5/30/23
to 'Dmitry Markman' via BBEdit Talk

Use Text -> Process Lines Containing... and enter this search string:

\d\d:\d\d:\d\d

Make sure "Grep" and "Delete matched lines" are checked.

— 
Rod



--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/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/8b13b1cd-1b61-475b-90cf-7530b3aeb928n%40googlegroups.com.

Neil Faiman

unread,
May 30, 2023, 10:09:31 AM5/30/23
to BBEdit Talk Mailing List
On May 30, 2023, at 8:23 AM, Otto Munters <ottom...@gmail.com> wrote:

Hello, I am a new BBEdit user and want to remove all timings from a srt file to use it as a text document. It looks like this now:
1
00:00:33,360 --> 00:00:45,060
Welcome. Lovely to see you all. We
should take our time to introduce

2
00:00:46,560 --> 00:00:52,380
the rules. Just like you have ashram
rules, we have rules for self inquiry.  

3
00:00:55,200 --> 00:01:01,080
Vedanta is an ancient tradition,
science of self inquiry

All the first two lines of each paragraph (page number and timing) I want to remove. I also want to remove the blank lines so that one large block of text remains.

I don’t know the exact rules, so I’m making a guess. The following pattern will remove all occurrences of

  • an (optional) empty line (no text at all), followed by
  • a line containing one or more digits at the beginning, and nothing else, followed by
  • a line
    • starting with a string of digits, decimal points, commas, and colons
    • followed by the string “ —> ”
    • followed by another string of digits, decimal points, commas, and colons
    • and nothing else.

Here’s the recipe. With the document you want to clean up open in a BBEdit window, open the find-and-replace dialog (Search menu -> Find…, or Command-F).

Paste the following string in the “Find:” field:

(?s)^\n?\d+\n[0-9.,:]+ --> [0-9.,:]+\n


Make sure the “Replace:” field is empty.

Check the “Grep” and “Wrap around” boxes. Clear the “Case sensitive”, “Entire word”, and “Selected text only” boxes.

Click “Replace All”.

When I do this with your example text in the document window, I end up with

Welcome. Lovely to see you all. We

should take our time to introduce

the rules. Just like you have ashram

rules, we have rules for self inquiry.  

Vedanta is an ancient tradition,

science of self inquiry


Detailed explanation of the Grep search string:

  • (?s) says that this search treats the entire document as the string to be processed, rather than processing each line independently.
  • ^ says to start searching at the start of a line.
  • \nmatches a new-line character if there is one. (i.e., in conjunction with the preceding ^, it matches an empty line.)
  • \d+ matches a string of one or more digits.
  • \n matches a new-line character. (In conjunction with the preceding \d+, it matches a line containing only a string of digits.)
  • [0-9.,:]matches a string of one or more digits, decimal points, commas, and/or colons.
  •  --> matches that specific string of characters. (You can’t see them here, but the spaces are part of the string — that is, it is the five characters space, hyphen, hyphen, greater-than, space.)
  • [0-9.,:]matches a second string of one or more digits, decimal points, commas, and/or colons.
  • \n matches a new-line character. (In conjunction with the preceding three elements, it matches a time-stamp line.)

Then the effect of the “Replace all” is to replace each such two-or-three line string with “nothing,” i.e., to delete it.

Cheers,
Neil Faiman

Fletcher Sandbeck

unread,
May 30, 2023, 10:09:40 AM5/30/23
to bbe...@googlegroups.com
The Pattern Playground on the Search menu is a great way to build up a pattern for search/replace. You can see interactively what it is going to match as you create it. I think this pattern works.

Search: ^[0-9:, -->]+\r
Replace: 

The caret sign anchors the search at the start of the line. The square brackets match any character contained within so we simply enumerate all the characters in the lines you want to get rid of and replace with an empty string. Any lines that contain a character other than a number or the other characters will be removed.

You can then use Remove Blank Lines on the Text menu to clean up any remaining blank lines.

[fletcher]


Otto Munters

unread,
May 30, 2023, 10:50:09 AM5/30/23
to BBEdit Talk

Thanks a lot for your help! I’m not behind my computer nog, but I’m sure that your answers are going  to help me. 😊
Op dinsdag 30 mei 2023 om 16:09:40 UTC+2 schreef Fletcher Sandbeck:
Reply all
Reply to author
Forward
0 new messages