Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Add leading zeros between "0x" and comma, to make a 8-digit hex number

    Help wanted · · · – – – · · ·
    4
    6
    108
    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.
    • Sankar S
      Sankar S last edited by

      Hello,
      I have a huge list of number that look like this:
      {0x1023350, 0x3014},
      {0x1023954, 0x3007},
      {0x1023960, 0x10F},
      {0x102396C, 0x2FF},
      {0x10219, 0x16},

      The output I want from this is all the above Hex numbers formatted to 8-digits using zero padding as follows:
      {0x01023350, 0x00003014},
      {0x01023954, 0x00003007},
      {0x01023960, 0x0000010F},
      {0x0102396C, 0x000002FF},
      {0x00010219, 0x00000016},

      How can I do this using regular expression ? Appreciate any help

      Alan Kilborn 1 Reply Last reply Reply Quote 1
      • Alan Kilborn
        Alan Kilborn @Sankar S last edited by Alan Kilborn

        @Sankar-S

        Try:

        Find what box: 0x(([[:xdigit:]]{7}\b)|([[:xdigit:]]{6}\b)|([[:xdigit:]]{5}\b)|([[:xdigit:]]{4}\b)|([[:xdigit:]]{3}\b)|([[:xdigit:]]{2}\b)|([[:xdigit:]]{1}\b))
        Replace with box: 0x(?{2}0)(?{3}00)(?{4}000)(?{5}0000)(?{6}00000)(?{7}000000)(?{8}0000000)${1}
        Search mode radiobuttons: press Regular expression

        There are simpler expressions; this was just a fast one I came up with.

        Learn to answer questions of this kind yourself in the future; start reading HERE and also check out the N++ user manual’s searching section HERE.

        Sankar S 1 Reply Last reply Reply Quote 4
        • Sankar S
          Sankar S @Alan Kilborn last edited by

          @Alan-Kilborn said in Add leading zeros between “0x” and comma, to make a 8-digit hex number:

          0x(?{2}0)(?{3}00)(?{4}000)(?{5}0000)(?{6}00000)(?{7}000000)(?{8}0000000)${1}

          Hi Alan,
          Thank you . That did work. Although I must spend sometime later to understand how this works :)

          PeterJones 1 Reply Last reply Reply Quote 1
          • PeterJones
            PeterJones @Sankar S last edited by

            @Sankar-S said in Add leading zeros between “0x” and comma, to make a 8-digit hex number:

            Although I must spend sometime later to understand how this works

            Alan linked you to the main group, but two of the concepts involved are:

            • Capture Groups (FIND): https://npp-user-manual.org/docs/searching/#capture-groups-and-backreferences
            • Conditional Substitution (REPLACE): https://npp-user-manual.org/docs/searching/#substitution-conditionals
            1 Reply Last reply Reply Quote 3
            • Terry R
              Terry R last edited by

              @Sankar-S said in Add leading zeros between “0x” and comma, to make a 8-digit hex number:

              Although I must spend sometime later to understand how this works

              Additionally, if you were to visit https://regex101.com/r/nxiyAH/1 you will see an explanation of @Alan-Kilborn’s regular expression (regex) and colour coded selections on your example.

              This site does an excellent job of explaining some regex, but do be careful as the flavor (of regular expressions) Notepad++ uses has some subtle differences.

              It is just another tool in the arsenal of a lot of regex coders.

              Terry

              1 Reply Last reply Reply Quote 2
              • Sankar S
                Sankar S last edited by

                @PeterJones @Terry-R , Thank you , I will check out these resources .

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors