• Login
Community
  • Login

Sequence number 1, 2, 3... Change to adding a 0

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 4 Posters 1.4k 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.
  • U
    Un Known
    last edited by Un Known Oct 27, 2023, 11:44 AM Oct 27, 2023, 9:10 AM

    Hi…

    I have a notepad++ document with my questions in this format:

    1-
    2-
    3-
    4-

    And I want now them to be:

    01-
    02-
    03-
    04-

    The problem is there are not consecutive in the document… I mean…

    1- How are you?

    A) Fine
    B) Fine
    C) Fine
    D) Fine

    2- How old are you?

    A) 21
    B) 21
    C) 21
    D) 21

    So i want to know if there is a method to secuence them like 01, 02, 03… despite they are not one below the other.

    There are 325 questions.

    Thanks.

    P C 2 Replies Last reply Oct 27, 2023, 1:05 PM Reply Quote 0
    • P
      PeterJones @Un Known
      last edited by PeterJones Oct 27, 2023, 1:06 PM Oct 27, 2023, 1:05 PM

      @Un-Known ,

      In one step, with just Notepad++? No. Notepad++ cannot natively handle mathematical replacements, as explained in this FAQ (which contains some of the workarounds mentioned below).

      If you allow for more than one step, or if you are willing to install a plugin, then yes.

      Until recently, I would have recommended a multi-step process, similar to:

      1. replace all newlines that don’t come before #- with a different character that you don’t use in your document, like a smiley face (\R(?!\d+-) ⇒ ☺)
      2. delete all the numbers before the - at the beginning of each combined line (^\d+(?=-) ⇒ empty)
      3. Use a column selection then Column Editor (Edit > Column Editor or Alt+C) to insert numbers starting at 1 with leading zeroes
      4. change the different-character back into newline sequence (☺ ⇒ \r\n for Windows EOL)

      But now that there are a couple of plugins that more easily handle mathy replacements, I’d suggest using one of those.

      For the Columns++ plugin, I am pretty sure that something like the following (derived from this FAQ section would work with Columns++ (and the author @Coises will correct me if I’m wrong):

      • Using the plugin’s search/replace (not Notepad++ search/replace)
        FIND = ^\d+-
        REPLACE = (?=3:match)-
        • where the 3 in that replacement means it will be three digits (001 - 325)
        • and the match in that replacement means

      And in the MultiReplace plugin, I think you would need to use the CNT variable in its search/replace feature.

      ----

      Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

      U 1 Reply Last reply Oct 27, 2023, 4:00 PM Reply Quote 3
      • U
        Un Known @PeterJones
        last edited by Oct 27, 2023, 4:00 PM

        @PeterJones

        Thnak you and thanks too for the FAQ`s!

        1 Reply Last reply Reply Quote 0
        • C
          Coises @Un Known
          last edited by Oct 27, 2023, 4:29 PM

          @Un-Known

          Your title and example suggests that the question numbers are already correct, you just want to add a zero before them, and you say you have 325 questions; so I wonder, do you want:

          01-
          02-
          ...
          09-
          010-
          011-
          ...
          099-
          0100-
          0101-
          ...
          0325-
          

          which is what your question, taken precisely, says? Or:

          001-
          002-
          ...
          009-
          010-
          011-
          ...
          099-
          100-
          101-
          ...
          325-
          

          which is what I think @PeterJones assumed you meant?

          Also, are the numbers themselves already correct (just missing the leading zeros), or do you need to renumber, too?

          If all you wanted was to add one zero before every question number, and the pattern follows your example that all question lines, and only question lines, start with a number, then all you need is:

          From the menu, select Search | Replace; in the dialog, set:

          Find what : ^(\d)
          Replace with: 0$1
          Search Mode : Regular expression

          and use the Replace All button.

          A 1 Reply Last reply Oct 29, 2023, 5:00 AM Reply Quote 2
          • A
            Adev Fu @Coises
            last edited by Adev Fu Oct 29, 2023, 5:09 AM Oct 29, 2023, 5:00 AM

            This post is deleted!
            1 Reply Last reply Reply Quote -3
            5 out of 5
            • First post
              5/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors