Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 1.3k 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.
    • Alan KilbornA
      Alan Kilborn @Chris Tanguay 0
      last edited by

      @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!

      Chris Tanguay 0C 1 Reply Last reply Reply Quote 2
      • Chris Tanguay 0C
        Chris Tanguay 0
        last edited by

        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!

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Chris Tanguay 0
          last edited by

          @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
          • Chris Tanguay 0C
            Chris Tanguay 0
            last edited by

            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.

            Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Chris Tanguay 0
              last edited by

              @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
              • PeterJonesP
                PeterJones @Chris Tanguay 0
                last edited by

                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
                • Chris Tanguay 0C
                  Chris Tanguay 0
                  last edited by

                  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
                  • Chris Tanguay 0C
                    Chris Tanguay 0 @Alan Kilborn
                    last edited by

                    @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!

                    PeterJonesP 1 Reply Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @Chris Tanguay 0
                      last edited by

                      @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.

                      Chris Tanguay 0C 1 Reply Last reply Reply Quote 0
                      • Chris Tanguay 0C
                        Chris Tanguay 0 @PeterJones
                        last edited by

                        @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