• Login
Community
  • Login

How do I change the first letter lowercase to uppercase in notepad++?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 4.9k 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.
  • M
    Mohamed Mohamed
    last edited by Jul 30, 2023, 12:20 PM

    I want to change all first letters from lowercase to uppercase inside square brackets in notepad++, for example from [gasps] to [Gasps]. But if it is the characters name inside square brackets, make all caps.
    This is what i have done and the outcome.
    Screenshot_5.png
    a5731398-8833-4ab6-a315-6e70a96835ca-image.png

    M 1 Reply Last reply Jul 30, 2023, 2:43 PM Reply Quote 1
    • M
      mkupper @Mohamed Mohamed
      last edited by mkupper Jul 30, 2023, 2:52 PM Jul 30, 2023, 2:43 PM

      @Mohamed-Mohamed You were close to what is needed. The [ and ] characters are special in the search part of a regular expression and so you need to put a \ in front of them.

      It’s not clear though if you want just the first letter or the entire thing inside the [ ... ] to be capitals.

      If the first letter then use
      Search for: [([a-z]+)]
      Replace with: [\u\1]

      If the entire word then use [\U\1] with a capital ‘U’ instead of lower case ‘u’ in the replace part.

      See https://npp-user-manual.org/docs/searching/#substitutions for how the \u and \U work in the replacement part of a regular expression.

      It’s also not clear if you want [Explosion] to become [EXPLOSION]. As you have match-case enabled the search for [a-z] would not match a capital ‘E’. If you want [EXPLOSION] then you can either turn the match-case tick box off or you can preface the search part with (?i) to ignore case (Search for (?i)[([a-z]+)]) or you can search for [([A-Za-z]+)] In https://npp-user-manual.org/docs/searching/#regular-expressions there are various \ followed by a letter things you can use to search for letters, lower case letters, etc. Use whatever you feel comfortable with.

      M 1 Reply Last reply Jul 30, 2023, 3:05 PM Reply Quote 2
      • M
        Mohamed Mohamed @mkupper
        last edited by Jul 30, 2023, 3:05 PM

        @mkupper Thank you it worked, but is it possible to make all characters names be capslock e.g. [JOHN].

        M 1 Reply Last reply Jul 30, 2023, 8:07 PM Reply Quote 0
        • M
          Mark Olson @Mohamed Mohamed
          last edited by Jul 30, 2023, 8:07 PM

          @Mohamed-Mohamed
          You’d need a | -separated list of all the characters’ names.

          For example, if the characters are named

          John
          Bob
          Mary
          Ellen
          Fred
          

          your regex becomes (?i)\\[(?:(John|Bob|Mary|Ellen|Fred)|([a-z]+))\\]
          and your replacement becomes [(?1\U${1}\E:(?2\u${2}))]
          Thus, you would convert

          [explosion]
          [crash]
          [john]
          yo dawg
          [Ellen]
          i herd u like regex
          [bob]
          so i made regex
          [boom]
          [pow]
          [mary]
          so u can regex
          [zap]
          [fred]
          with regex
          

          into

          [Explosion]
          [Crash]
          [JOHN]
          yo dawg
          [ELLEN]
          i herd u like regex
          [BOB]
          so i made regex
          [Boom]
          [Pow]
          [MARY]
          so u can regex
          [Zap]
          [FRED]
          with regex
          
          1 Reply Last reply Reply Quote 2
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors