Community
    • Login

    enclose each character of string in {}

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 Posters 1.6k Views 3 Watching
    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.
    • Bill KristyB Offline
      Bill Kristy
      last edited by

      I have a long string of random characters, and I need each character enclosed in brackets.

      For example, I want to transform
      abcd
      into
      {a}{b}{c]{d}

      Can I do this with Notepad++? Or alternative suggestion please?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @Bill Kristy
        last edited by PeterJones

        @Bill-Kristy ,

        Using

        • Search Mode = Regular Expression
        • Find What= .
        • and Replace With = {$1}

        you should get what you want.

        update: sorry for the typo: as others clarified below, should be {$0}

        -—

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        Bill KristyB Alan KilbornA 2 Replies Last reply Reply Quote 4
        • Bill KristyB Offline
          Bill Kristy @PeterJones
          last edited by

          @PeterJones Thank you very much for your reply!

          Close, but what that got me was:
          {}{}{]{}

          In other words, a pair of empty brackets for each character.

          mkupperM 1 Reply Last reply Reply Quote 0
          • Alan KilbornA Offline
            Alan Kilborn @PeterJones
            last edited by

            I think @PeterJones made a typo; should be:

            Replace With = {$0}

            Bill KristyB 1 Reply Last reply Reply Quote 2
            • mkupperM Offline
              mkupper @Bill Kristy
              last edited by mkupper

              @Bill-Kristy, @PeterJones had a typo.

              Regular expression search for .
              Replace with {$0}

              An alternative is to search for (.) and to replace with {$1}

              $0 in a replacement part is the entire thing that was matched in the search part.
              $1 in a replacement part is the first capture group which is the thing in (parentheses)

              1 Reply Last reply Reply Quote 1
              • Bill KristyB Offline
                Bill Kristy @Alan Kilborn
                last edited by

                @Alan-Kilborn @mkupper Thank you very much everyone, {$0} did the trick! Pure gold for me, thanks again!

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors