• Login
Community
  • Login

Delete all-cap words

Scheduled Pinned Locked Moved General Discussion
22 Posts 7 Posters 1.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    Terry R @LordP666
    last edited by Oct 3, 2024, 7:40 AM

    @LordP666
    Here is one possible solution.

    First remove all lines containing no lower case characters, but they could contain punctuation characters. Then mark other lines if they contain say more than 3 (or some suitable number) of upper case characters. You would then check those and unmark ones you want to keep, removing the lines left marked.

    Terry

    L 1 Reply Last reply Oct 3, 2024, 10:02 AM Reply Quote 1
    • L
      LordP666 @Terry R
      last edited by LordP666 Oct 3, 2024, 8:18 AM Oct 3, 2024, 8:17 AM

      @Terry-R

      “Sometimes we can’t get you everything” - I’m very OK with being close ;)

      As I said, having an exception would be a massive improvement - I would still have to edit odds and end like “OK”, or “DCI”…but it seems that 99% of what I had to edit were freestanding "I"s and also in “I’ve”, “I’m”, “I’d” - and these are not 100% all caps.

      I suppose what I want is to delete words in all caps, and not ones where there are a mix, such as proper names. But that first person “I” is a killer.

      1 Reply Last reply Reply Quote 0
      • L
        LordP666 @Terry R
        last edited by Oct 3, 2024, 10:02 AM

        @Terry-R

        I decided to try OpenAI where I could keep refining my objective and finally arrived at: I want the expression to delete lines where all the letters are capitalized but to exclude lines that have lowercase letters.

        It gave me this: ^(?!.[a-z])([A-Z]+(\s+[A-Z]+))?$

        I tried it and nothing changed.

        LOL

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by guy038 Oct 3, 2024, 7:20 PM Oct 3, 2024, 12:42 PM

          Hello, @lordp666, @terry-R, @mark-olson, @coises and All,

          I’m a bit of a hurry because I’ve got an appointement at a ski shop to buy some new ski boots ! So I cannot develop my solution, presently.


          But just try the following regex S/R which suppresses all subtitle lines containing uppercase letters or digits ONLY, except for specific lines containing the words OK, DI and I.

          • SEARCH (?-si)^(?!\d\d)(?!\b(OK|DI|I)\b)[\u\d]+(?:[[:punct:]\h]+(?!\b(OK|DI|I)\b)[\u\d]+)*$(\R|\z)

          • REPLACE Leave EMPTY

          For example, from this INPUT text :

          14
          00:00:26,960 -> 00:00:29,040
          CALL DISCONNECTS
          DRAMATIC MUSIC
          KNOCK AT DOOR
          And I’d tell you that that was
          "OK, I won’t go then," but then
          DOOR CLOSES, KEY TURNS
          I
          T
          TE
          TEST
          TEST1
          T OK
          TE OK
          TEST OK
          TEST1 OK
          WORD1 WORD2 BLA
          WORD1 WORD2 BLA
          WORD1 WORD2 BLA
          WORD1 WORD2 OK BLA
          WORD1 WORD2 DI BLA
          WORD1 WORD2 I  BLA
          TOKT
          ABC TOKT
          

          You would be left with this OUTPUT one :

          14
          00:00:26,960 -> 00:00:29,040
          And I’d tell you that that was
          "OK, I won’t go then," but then
          I
          T OK
          TE OK
          TEST OK
          TEST1 OK
          WORD1 WORD2 OK BLA
          WORD1 WORD2 DI BLA
          WORD1 WORD2 I  BLA
          

          As you can see, after the sequence number and duration, it just remains lines containing the word I, OK or DI, in uppercase !

          See you later

          Best Regards

          guy038

          L 1 Reply Last reply Oct 3, 2024, 1:01 PM Reply Quote 1
          • L
            LordP666 @guy038
            last edited by Oct 3, 2024, 1:01 PM

            @guy038

            Wow. That worked really well - I’ll have to ask OpenAI to parse it for me as I only have the tiniest knowledge of this stuff.

            Amazingly, one line that should not have been removed…was not removed. It was: PE.

            Another one that passed the test was this: I L-O-V-E.

            Where the character is reading the first letters of separate lines.

            I am sure that there will be other words than “DI” or “OK” - but man, it beats editing 70-80 lines with that pesky first person “I”.

            I am in awe - thank you so much for your help.

            1 Reply Last reply Reply Quote 0
            • C
              Coises @LordP666
              last edited by Oct 3, 2024, 5:39 PM

              @LordP666 said in Delete all-cap words:

              @Coises

              I asked for help on this precisely because Subtitle Edit didn’t work. It does not see these likes as “hearing impaired” because they are not in any sort of brackets or parentheses.

              Are you sure you checked the box Remove line if UPPERCASE (not Only if text is UPPERCASE under Remove text before a colon (:), which is something different) in the Remove text for hearing impaired dialog?

              Which lines are listed in the bottom half of the dialog changes as you change settings at the top.

              Testing with Subtitle Edit 4.0.8 after adding the lines you gave as examples, I find them to be detected in the dialog when I check that box, and removed when Apply or OK is clicked.

              L 1 Reply Last reply Oct 4, 2024, 3:00 PM Reply Quote 0
              • G
                guy038
                last edited by guy038 Oct 4, 2024, 11:37 AM Oct 4, 2024, 11:26 AM

                Hi, @lordp666, @terry-R, @mark-olson, @coises and All,

                Glad to see that this search regex meets your needs, globally !


                I didn’t understand a sentence of your reply. You said :

                Amazingly, one line that should not have been removed…was not removed. It was: PE.
                

                Well …

                • If you do not want to keep the lines containing also the word PE in uppercase, simply use my previous search regex :

                  • SEARCH (?-si)^(?!\d\d)(?!\b(OK|DI|I)\b)[\u\d]+(?:[[:punct:]\h]+(?!\b(OK|DI|I)\b)[\u\d]+)*(\R|\z)

                • If you do want to keep the lines containing also the word PE in uppercase, use the following search regex :

                  • SEARCH (?-si)^(?!\d\d)(?!\b(PE|OK|DI|I)\b)[\u\d]+(?:[[:punct:]\h]+(?!\b(PE|OK|DI|I)\b)[\u\d]+)*(\R|\z)

                Regarding the line containing the string I L-O-V-E, it wouldn’t be sensible to find a suitable regex for such a case ! You’ll have to parse your text and decide whether you keep, or not, this kind of line and some other very specific ones :-(

                However, in order to help you with this task, AFTER the global first replacement above, you could follow this simple road map :

                • Move to the very beginning of your file to parse

                • Open the Mark dialog ( Ctrl + M )

                  • SEARCH (?-i)^[\u\h[:punct:]]+$

                  • Uncheck all box options

                  • Check the Bookmark line, Purge for each search and Wrap around box options

                  • Select the Regular expression mode

                  • Click on the Mark All button

                • Now hit, successively, on the F2 key to reach all the remaining lines which could possibly be deleted or kept :-)

                Cheers,

                guy038

                P.S. :

                Next time, I’ll give you some hints about the regexes used !

                L 1 Reply Last reply Oct 4, 2024, 2:54 PM Reply Quote 0
                • L
                  LordP666 @guy038
                  last edited by LordP666 Oct 4, 2024, 2:58 PM Oct 4, 2024, 2:54 PM

                  @guy038

                  Sorry, I meant that it worked very well - that line in the dialogue was just this: PE

                  Meaning “Physical Education”.

                  It was NOT a “Hearing Impaired” part of the subtitles and should not have been deleted.

                  As I said before, I played with OpenAI trying to clarify what I wanted to do and had come to the (false) conclusion that I wanted to delete ALL lines that had no lowercase letters.

                  That one single line in the dialogue showed me that it would be a mistake to delete all lines without lowercase.

                  Your suggestion worked better than I realized.

                  Thanks again.

                  EDIT: I also use OpenAI to decode these search strings and I wonder what you think of its abilities? It gave me this:

                  ChatGPT
                  Certainly! Let’s break down the regular expression (?-si)^(?!\d\d)(?!\b(OK|DI|I)\b)[\u\d]+(?:[[:punct:]\h]+(?!\b(OK|DI|I)\b)[\u\d]+)*$(\R|\z) piece by piece:

                  (?-si): This is a mode modifier.

                  s: This option allows . to match newline characters.
                  i: This option makes the matching case insensitive.
                  -si: The minus sign indicates that both options are turned off. So, . will not match newlines, and the matching will be case sensitive.
                  ^: Asserts the start of a line.

                  (?!\d\d): A negative lookahead assertion that checks if the string does not start with two digits. If the string starts with two digits, the match will fail.

                  (?!\b(OK|DI|I)\b): Another negative lookahead that ensures that the string does not contain the whole words “OK”, “DI”, or “I”. The \b asserts a word boundary, meaning that “OK”, “DI”, or “I” must not be present as complete words.

                  [\u\d]+: Matches one or more characters that are either:

                  \u: A Unicode character (the exact definition may depend on the specific implementation, often it means any character except control characters).
                  \d: Any digit (0-9).
                  (?: … ): This is a non-capturing group, meaning it groups part of the regex together without capturing the matched text for back-referencing.

                  [[:punct:]\h]+: Inside the non-capturing group, this matches one or more characters that are:

                  [:punct:]: Any punctuation character.
                  \h: Any horizontal whitespace (spaces or tabs).
                  (?!\b(OK|DI|I)\b): Again, another negative lookahead to ensure that after the punctuation and whitespace, the words “OK”, “DI”, or “I” do not appear.

                  [\u\d]+: After the punctuation and whitespace, this matches one or more characters that are either Unicode characters or digits.

                  *: The non-capturing group can repeat zero or more times, allowing for multiple segments of the pattern.

                  $: Asserts the end of a line.

                  (\R|\z): This matches either:

                  \R: Any line break (newline character).
                  \z: The end of the string, which ensures that the match goes to the very end of the input.
                  Summary
                  This regex matches a string that:

                  Does not start with two digits.
                  Does not contain the whole words “OK”, “DI”, or “I”.
                  Contains one or more Unicode characters or digits.
                  May have segments of punctuation/whitespace followed by more Unicode characters or digits.
                  The whole match must end at the line’s end or the end of the string.
                  Let me know if you need further clarification on any part!

                  A 1 Reply Last reply Oct 4, 2024, 3:19 PM Reply Quote 0
                  • L
                    LordP666 @Coises
                    last edited by Oct 4, 2024, 3:00 PM

                    @Coises

                    Thanks for the tip. I don’t normally mess around with the setting as I’m not 100% sure about some of them. I will check it out in the future.

                    Now I’m wondering if SubtitleEdit would have removed that one line I described to guy038, among others.

                    PE

                    1 Reply Last reply Reply Quote 0
                    • A
                      Alan Kilborn @LordP666
                      last edited by Oct 4, 2024, 3:19 PM

                      @LordP666 said in Delete all-cap words:

                      I also use OpenAI to decode these search strings and I wonder what you think of its abilities

                      Postings of AI generated content are disallowed on this forum.
                      Anyone that wanted to see what AI thought of the regular expression can run it through an AI for themselves.

                      L 1 Reply Last reply Oct 4, 2024, 4:06 PM Reply Quote 1
                      • P
                        PeterJones
                        last edited by Oct 4, 2024, 3:40 PM

                        In back-and-forth between @Coises and @LordP666:

                        You would find it much easier to use Subtitle Edit .
                        …
                        I asked for help on this precisely because Subtitle Edit didn’t work.
                        …
                        Testing with Subtitle Edit 4.0.8 …
                        …
                        Now I’m wondering if SubtitleEdit would have …

                        And as a reminder, this Forum is for Notepad++, not Subtitle Edit. If you two want to continue to talk about that alternative, you can use the private chat of the forum if you want. But let’s keep the focus of this conversation on possible Notepad++ solutions (without resorting to probabilistic Generative AI hallucinations).

                        1 Reply Last reply Reply Quote 1
                        • L
                          LordP666 @Alan Kilborn
                          last edited by Oct 4, 2024, 4:06 PM

                          @Alan-Kilborn

                          Sorry, won’t happen again.

                          1 Reply Last reply Reply Quote 0
                          • G
                            guy038
                            last edited by guy038 Oct 5, 2024, 9:09 PM Oct 5, 2024, 9:07 PM

                            Hi, @lordp666, @terry-R, @mark-olson, @coises, @peterjones and All,

                            @lordp666, I’m simply blown away by the accuracy of ChatGPT’s answers. Truly amazing !

                            Sincerely, the accuracy of the response is impressive. Just one small error, however:


                            With our Boost regex engine, if you have used the -i modifier or if you have ticked the Match case box :

                            • The \l syntax represents a single lowercase Unicode letter

                            • The \u syntax represents a single uppercase Unicode letter

                            and :

                            • The [[:alnum:]] syntax is a shortcut for [\d\l\u], so any Unicode letter or digit

                            • The \w or [[:word:]] syntaxes are a shortcut for [_\d\l\u], so any Unicode letter, digit or the underscore

                            So, apart from this particular point, the rest of ChatGPT’s reply, including the summary, is completely accurate !

                            Sorry, no need to give you any further explanations !


                            Ah… coders everywhere : unite and fight ! In the ( very ) near future, AI is going to replace us and leave us out in the cold ;-))

                            BR

                            guy038

                            1 Reply Last reply Reply Quote 2
                            19 out of 22
                            • First post
                              19/22
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors