• Login
Community
  • Login

Batch Convert case in multiple open files (maybe regex?)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 3 Posters 1.4k 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.
  • C
    Chris Tanguay 0
    last edited by Jul 28, 2021, 3:03 PM

    Let’s say I have 10 text files all open at once, and I want to convert the text in all of those to UPPER CASE. Right now, I have to start in the first file, hit CTRL A, then CTRL-SHIFT-U. File #1 done. Then, I have to click on next file tab, and “rinse & repeat” file by file. I’m looking for a way to change case on these opened files all at once. There’s no such thing as a magical expanded version of CTRL-A, which selects all text in ALL OPENED TEXT FILES? That would be cool, but probably not. Yes, I could macro record the CTRL-A and CTRL-SHIFT-U combo, but I’d still have to go from file to file and run it.
    What about some REGEX syntax that would accomplish the same thing? I’m still finding my way with REGEX, so could use syntax examples. Would like to have the syntax for UPPERCASE, lowercase, Proper Case, and Sentence case, if anyone can help. Thx! - Chris

    A 1 Reply Last reply Jul 28, 2021, 3:26 PM Reply Quote 0
    • A
      Alan Kilborn @Chris Tanguay 0
      last edited by Jul 28, 2021, 3:26 PM

      @Chris-Tanguay-0

      So you have to do a Replace in Files to do something like this.
      Yes, use regex to replace . with \U$0.
      There are other ways to do it, of course, you could do the find on non-uppercase and only convert those matches, for instance.
      I’d say to definitely do a backup on all your files first!

      C 1 Reply Last reply Aug 19, 2021, 8:15 PM Reply Quote 2
      • C
        Chris Tanguay 0
        last edited by Aug 9, 2021, 3:19 PM

        Alan, tested it, worked perfect! Replacing . with \U$0 (in all files) changed all text to UPPER CASE in one step.
        Thank you! I’ve macro’d that and will be using it a lot.
        Can I ask for a few more syntaxes?
        (1) What would be the Regex to change all to lower case? Would it be replace . with \L$0
        (2) … To Proper Case?
        (3) … To Sentence case?
        (4) Can you briefly verbalize what the syntax means here? Just trying to understand it better.
        (5) Here’s the better question I should be asking. I can see the WOW factor and all the potential in learning all this REGEX. I want to learn this stuff. Is there a site you’d recommend as a way to get into understanding REGEX that is NOOB-friendly? I’ve done some coding in the past, but never have tackled regex. Any recommedations? Thx!

        A 1 Reply Last reply Aug 9, 2021, 3:28 PM Reply Quote 0
        • A
          Alan Kilborn @Chris Tanguay 0
          last edited by Aug 9, 2021, 3:28 PM

          @Chris-Tanguay-0

          (1) Yep, \L$0
          (2) Search for (\w)(\w+) and replace with \U${1}\L${2} (depending up data there may be some limitations)
          (3) I don’t think there is going to be a nice equivalent for “sentence case”
          (4) Syntax is “match any character” (from the .) and replace the entire match (from the $0) with its uppercase equivalent (from the leading \U)
          (5) Great starting info: see the FAQ HERE

          1 Reply Last reply Reply Quote 2
          • C
            Chris Tanguay 0
            last edited by Aug 9, 2021, 7:10 PM

            Thanks again! This will save me lots of time (and clicks).
            Weird, I’ve been trying to access https://npp-user-manual.org/docs/searching/#regular-expressions, but page keeps timing out. Anyone else? Maybe it’s dead. I’ll poke around some of the other pages referenced on the FAQ
            Love notepad++ more each day.

            A P 2 Replies Last reply Aug 9, 2021, 7:35 PM Reply Quote 0
            • A
              Alan Kilborn @Chris Tanguay 0
              last edited by Aug 9, 2021, 7:35 PM

              @Chris-Tanguay-0 said in Batch Convert case in multiple open files (maybe regex?):

              I’ve been trying to access https://npp-user-manual.org/docs/searching/#regular-expressions, but page keeps timing out. Anyone else? Maybe it’s dead. I’ll poke around some of the other pages referenced on the FAQ

              Very much alive for me.

              1 Reply Last reply Reply Quote 0
              • P
                PeterJones @Chris Tanguay 0
                last edited by Aug 9, 2021, 7:37 PM

                Very much alive for me.

                and for me.

                @Chris-Tanguay-0 , you might try again – maybe you had a brief network issue. Or maybe you’re using IPv6, which apparently sometimes has issues reaching the online user manual

                1 Reply Last reply Reply Quote 0
                • C
                  Chris Tanguay 0
                  last edited by Aug 9, 2021, 8:06 PM

                  Thanks, all. Just figured out why. I’m at work, and our Sophos firewall says site is hosted from Cyprus. Just had to ask our IT people to unblock. Good times!

                  1 Reply Last reply Reply Quote 1
                  • C
                    Chris Tanguay 0 @Alan Kilborn
                    last edited by Aug 19, 2021, 8:15 PM

                    @Alan-Kilborn I’m having a strange thing going on. I have maybe 8 text files open at same time, not all that long (they are subtitle srt files). I want them all upper case for text. But, when I try replacing . with \U$0 and I choose REPLACE IN ALL FILES, Notepad+ locks up. I let it sit there for a good 2 minutes thinking it was just taking a long time, but nope, I had to crash out of the program. I wonder why it’s having issues with this.
                    Any thoughts on this, or… maybe some alternate syntax I can try. I’m running on a fairly robust windows 10 machine, so it’s not processing power…
                    Thanks!

                    P 1 Reply Last reply Aug 19, 2021, 8:19 PM Reply Quote 0
                    • P
                      PeterJones @Chris Tanguay 0
                      last edited by Aug 19, 2021, 8:19 PM

                      @Chris-Tanguay-0 ,

                      They may not be huge, but if you’re doing FIND = . and REPLACE = \U$0, then it’s trying to upper-case every byte in the file, even on bytes that are not letters or already uppercase. Sometimes, patience is required: even if it’s only 1Mb, that’s still a million attempts to uppercase the character.

                      Also, you might want to restrict it to only work on lowercase letters, like FIND = [a-z]+ and the same replacement.

                      C 1 Reply Last reply Aug 19, 2021, 8:36 PM Reply Quote 0
                      • C
                        Chris Tanguay 0 @PeterJones
                        last edited by Aug 19, 2021, 8:36 PM

                        @PeterJones That (and as you said, a little patience) worked. The [a-z]+ cuts the time in half.
                        Thanks!

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