• Login
Community
  • Login

Replace lowercase with uppercase between brackets

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 4 Posters 2.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.
  • H
    Hank K
    last edited by Aug 5, 2021, 9:11 PM

    Need to change varying text between square brackets to UPPERCASE.

    Change [help wanted] to [HELP WANTED]

    Found an Tried the following regex:

    [([^]\r\n]*)] … Invalid regular expression!
    Invalid regular expresion.jpg (see pic attached)

    (?-s)[.*?] … All this does is finds . and/or ? in the file

    [([^]]*)] … Invalid regular expression

    1 Reply Last reply Reply Quote 1
    • T
      Terry R
      last edited by Terry R Aug 5, 2021, 9:39 PM Aug 5, 2021, 9:38 PM

      @Hank-K said in Replace lowercase with uppercase between brackets:

      Need to change varying text between square brackets to UPPERCASE.

      Your regex was close and it gave me a starting point for one that does work.

      Find What:(?<=\[)([^]\r\n]+)
      Replace With:\U\1

      See if that helps you. Now currently it will not edit a string if that string goes over 2 (or more) lines. If you need to allow for multiple lines you could change the find what code to (?<=\[)([^]]+).

      Give it a go and please do tell us how you got on, even if not working and let us know what strings it missed. We could alter to suit.

      Terry

      PS forgot to say I also changed the * to a +. In order to change any characters to upper case there must be at least 1 otherwise no sense in selecting it.

      1 Reply Last reply Reply Quote 2
      • H
        Hank K
        last edited by Aug 5, 2021, 10:46 PM

        Tried both same, Invalid regular expression!
        Invalid regular expresion R1.jpg

        Does it work for you ? Here’s the exact portion of the text:

        1
        00:00:01,042 --> 00:00:02,919
        [door squeaks open]

        2
        00:00:02,961 --> 00:00:04,337
        [clears throat]

        3
        00:00:04,379 --> 00:00:06,172
        [keys jangle]

        Thanks for the assist Terry … what am I doing wrong ?

        P 1 Reply Last reply Aug 5, 2021, 10:58 PM Reply Quote 0
        • A
          Alan Kilborn
          last edited by Alan Kilborn Aug 5, 2021, 10:58 PM Aug 5, 2021, 10:57 PM

          So, Terry probably meant the regex to be (?<=\\[… but this site has some weirdness with posting the backslash-then-left-bracket syntax.

          The fact that the first [ is not escaped is probably the problem here.

          T 1 Reply Last reply Aug 5, 2021, 11:00 PM Reply Quote 3
          • P
            PeterJones @Hank K
            last edited by PeterJones Aug 5, 2021, 10:59 PM Aug 5, 2021, 10:58 PM

            @Hank-K said in Replace lowercase with uppercase between brackets:

            Invalid regular expression!

            The forum mangles backslash followed by [ , even in `backticks`, which make just about everything appear literal

            The first should be bd9b459f-1abe-4727-a1e9-edef1d7f4719-image.png

            The second should be 26aef4d2-31ea-4489-b374-b4cba11cc3ce-image.png

            (edit: i unnecessarily escaped the ] in the first one but not the second. talk about consistency; it’ll still find the same things)

            1 Reply Last reply Reply Quote 2
            • T
              Terry R @Alan Kilborn
              last edited by Terry R Aug 5, 2021, 11:02 PM Aug 5, 2021, 11:00 PM

              @Alan-Kilborn said in Replace lowercase with uppercase between brackets:

              The fact that the first [ is not escaped is probably the problem here.

              Yep, right first time. I forgot that bloody interpreter has a way with certain characters, thanks @Alan-Kilborn for providing that fix.

              Terry

              PS apologies @Hank-K , good to see that the seasoned forum members are there to help out. We’ll get you there eventually.

              PPS, so the alternate regex also needs the \ added in the same location.

              1 Reply Last reply Reply Quote 0
              • H
                Hank K
                last edited by Aug 5, 2021, 11:06 PM

                The accomplishment of an aim or purpose.
                SUCCESS

                Thanks so MUCH for the quick replies GUYS … 2 thumbs ~~

                H 1 Reply Last reply Aug 5, 2021, 11:16 PM Reply Quote 0
                • H
                  Hank K
                  last edited by Hank K Aug 5, 2021, 11:11 PM Aug 5, 2021, 11:10 PM

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • H
                    Hank K @Hank K
                    last edited by Aug 5, 2021, 11:16 PM

                    If I wanted to ignore existing UPPERCASE between the brackets ? ? ?
                    Using it in “Find in Files” mode … have a lot existing cases.

                    Trying to MATCH existing files is what started this epic journey … lol

                    1 Reply Last reply Reply Quote 0
                    • T
                      Terry R
                      last edited by Aug 5, 2021, 11:26 PM

                      @Hank-K said in Replace lowercase with uppercase between brackets:

                      If I wanted to ignore existing UPPERCASE between the brackets ? ? ?

                      That would complicate matters and is probably unnecessary as you want to make all (alpha) characters inside the [] uppercase, who cares if the regex picks one set which is already so, it doesn’t change the outcome, still upper case characters are produced.

                      At the moment the regex picks ALL the characters together, so if some were already upper case do you wish to exclude those and only convert the remainder to upper case. That could be done with a regex, but honestly I think it serves no useful purpose. The conversion to uppercase is what matters, unless we are missing something you wish to convey but haven’t been able to so far?

                      Terry

                      1 Reply Last reply Reply Quote 1
                      • H
                        Hank K
                        last edited by Aug 6, 2021, 12:23 AM

                        NP …Thanks again Terry … Cheers

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