Community
    • Login

    How to find numbers and start new lines with the numbers

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 4 Posters 4.9k 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.
    • marko marinM Offline
      marko marin
      last edited by marko marin

      Dear community,
      I know how to find numbers in text but I don’t know how to start new lines with those numbers. I want to start new lines with those numbers (which are increasing).
      The text is ;
      “1. “It isn’t so foggy today as it was yesterday” 2. “You can keep that book, if you like, Joan”,3. “Are you leaving today or tomorrow morning?” 4. “How far is it? And how long will it take me to get there?” 5. “Nothing grows in my garden. It never gets any sun”,”
      What I want is;
      “1. “It isn’t so foggy today as it was yesterday”
      2. “You can keep that book, if you like, Joan”,
      3. “Are you leaving today or tomorrow morning?”
      4. “How far is it? And how long will it take me to get there?”
      5. “Nothing grows in my garden. It never gets any sun”,”
      without losing the digital numbers at the beginning of the lines.
      Marin

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

        • Find what : (.)(?=\d+\.)
        • Replace with : $1\n
        • ☑ Regular Expression

        Finds a single character followed by one or more digit characters followed by a period.
        Replaces with the single character, a newline, and leaves the original digit(s)+period intact.

        PS: see FAQ Desk: Where to find REGEX Documentation

        Scott SumnerS 1 Reply Last reply Reply Quote 3
        • Scott SumnerS Offline
          Scott Sumner @PeterJones
          last edited by

          @PeterJones

          I would just make this slight tweak, as probably most users including the OP are using Windows and thus expect Windows line-endings:

          Replace with zone: $1\r\n

          1 Reply Last reply Reply Quote 3
          • marko marinM Offline
            marko marin
            last edited by

            It worked well for me
            Great thanks…

            1 Reply Last reply Reply Quote 1
            • PeterJonesP Offline
              PeterJones
              last edited by

              @Scott-Sumner,

              Thanks. Some of the programming languages I use are EOL-aware, so when I output \n, it actually does CRLF on Windows; thus, I sometimes forget in regex substitutions that \n is really just the LF portion (and since Notepad++ showed a new line between, and I didn’t have line-endings visible, when I tried the regex, I didn’t notice my mistake).

              1 Reply Last reply Reply Quote 4
              • MarkomarinM Offline
                Markomarin
                last edited by

                This solution created a problem with double digit numbers. The first digit and the second digit becomes separate in lines. What can I do to solve it?

                Scott SumnerS 1 Reply Last reply Reply Quote 0
                • Scott SumnerS Offline
                  Scott Sumner @Markomarin
                  last edited by

                  @Markomarin

                  Maybe @PeterJones 's solution was a bit advanced for a regular expression noob. So maybe in the adjustment to handle multiple digits, it should also be simplified.

                  I’d be looking at how to find one or more digits followed by a literal .…and then replace that match with a line-ending (\r\n on windows, \n on linux) followed by the original match text (hint on that last part: Use $0).

                  Given that and your recent study of regular expressions, you should be able to take it to its completion.

                  1 Reply Last reply Reply Quote 1
                  • PeterJonesP Offline
                    PeterJones
                    last edited by

                    @Markomarin / @marko-marin ,

                    @Scott-Sumner is trying to help you to learn for yourself, and I applaud that effort on his part. My “PS: see FAQ Desk: Where to find REGEX Documentation” from three months ago will link you to some of the documentation that could help you research.

                    But as an alternative to his $0 hints (which may① be a better solution than mine), in the spirit of TIMTOWTD under which I learned my regexen: starting once again with my Find What : (.)(?=\d+\.) and Replace With : $1\r\n (as appropriately corrected by Scott earlier), by changing the first dot . in my original expression to a two-character escape sequence, I could parse

                    1. “It isn’t so foggy today as it was yesterday” 2. “You can keep that book, if you like, Joan”,3. “Are you leaving today or tomorrow morning?” 4. “How far is it? And how long will it take me to get there?” 5. “Nothing grows in my garden. It never gets any sun” 11. "Ours goes to Eleven" 12. "A dozen or more"
                    

                    to become

                    1. “It isn’t so foggy today as it was yesterday” 
                    2. “You can keep that book, if you like, Joan”,
                    3. “Are you leaving today or tomorrow morning?” 
                    4. “How far is it? And how long will it take me to get there?” 
                    5. “Nothing grows in my garden. It never gets any sun” 
                    11. "Ours goes to Eleven" 
                    12. "A dozen or more"
                    

                    … which is, I believe, what you now want.

                    As a further hint for what escape sequence to look for in the documentation: if the original dot . meant “find any character”, what might you want to do instead of finding any character. (Such as “find any character that’s not a flibberty-gibbert”, for some reasonable replacement for “flibberty-gibbert”)

                    ①: If using the sequence I believe he’s going for (which has one escape, one modifier, and one escape – with a total of five characters in the matching sequence), the first line may get a newline before it. Thus, for you, I would recommend going down both paths, and seeing which comes closer to your actual requirements.

                    But definitely: if you’re going to do more than the one regular expression you originally asked for, it will behoove you to study the documents, and practice, and start modifying it on your own, so you learn.

                    1 Reply Last reply Reply Quote 1
                    • PeterJonesP Offline
                      PeterJones
                      last edited by

                      (argh, typo. That should have been TIMTOWTDI… where’d my I go?)

                      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