Community
    • Login

    How do I join specific long lines that should be a single line (was: "Help.. how to...")

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 4 Posters 1.1k 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.
    • PeterJonesP
      PeterJones @Terry R
      last edited by

      @Terry-R,

      Leave the Replace With field empty, so this will delete the end of line where necessary.

      Do you want to leave it empty, or replace it with a space?

      I think yours was too aggressive, even with a space:

      BEFORE

      Question:
      
      1- This question originally spread
      across multiple lines?:
      
      
      A) This answer also started
      as two lines
      B) To Be or Not To Be
      C) I am not right
      D) Don't even think of guessing D
      
      ...
      
      9- Short Question
      
      A) Short Answer
      B) Be Short
      C) See, I am short
      D) Done
      
      13- Another question originally spread
      across multiple lines?:
      
      
      A) Apples
      B) Not the answer,
      but spread across multiple lines
      C) Cats!
      D) Dogs. Run away,
      run away!
      

      AFTER (without space)

      Question:1- This question originally spreadacross multiple lines?:
      A) This answer also startedas two lines
      B) To Be or Not To Be
      C) I am not right
      D) Don't even think of guessing D...9- Short Question
      A) Short Answer
      B) Be Short
      C) See, I am short
      D) Done13- Another question originally spreadacross multiple lines?:
      A) Apples
      B) Not the answer,but spread across multiple lines
      C) Cats!
      D) Dogs. Run away,run away!
      

      AFTER (with space):

      Question:  1- This question originally spread across multiple lines?:  
      A) This answer also started as two lines
      B) To Be or Not To Be
      C) I am not right
      D) Don't even think of guessing D  ...  9- Short Question 
      A) Short Answer
      B) Be Short
      C) See, I am short
      D) Done  13- Another question originally spread across multiple lines?:  
      A) Apples
      B) Not the answer, but spread across multiple lines
      C) Cats!
      D) Dogs. Run away, run away!  
      

      I was going to suggest something like ^(\d+-|[A-Z]\))(.*?)\R((?!\d+-|[A-Z]\)|\R).*$) replace with $1$2 $3, but you beat me again, and I think a hopefully-small tweak to yours would bring it in to working, without getting as complicated as mine.

      @Un-Known ,

      When asking questions, it’s best to have a meaningful title (even if you have to translate it from your native language). “Help… how to…” doesn’t tell the person looking at the list of posts anything about your post. On the other hand, “How do I join specific long lines that should be a single line” would tell the reader instantly what you are trying to do.

      Also, given this is a search-and-replace question, here are some useful references for helping you ask such questions, which helps us give better answers.

      • 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
      Alan KilbornA Terry RT PeterJonesP 3 Replies Last reply Reply Quote 2
      • Alan KilbornA
        Alan Kilborn @PeterJones
        last edited by

        @PeterJones said in Help.. how to...:

        How do I join specific long lines that should be a single line

        A moderator should change this thread’s title to exactly that. :-)

        1 Reply Last reply Reply Quote 0
        • Terry RT
          Terry R @PeterJones
          last edited by Terry R

          @PeterJones said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):

          Do you want to leave it empty, or replace it with a space?

          I think yours was too aggressive, even with a space:

          Very possibly. I was looking at the examples provided and of course it’s just made up stuff, gibberish. The after examples don’t match up either with blabla becoming bla bla.

          So I assumed there will likely be a bit of to and fro before OP becomes happy. My solution at least will let them know it’s possible and they need to sort out proper examples!

          Cheers
          Terry

          PS next time provide your solution before using moderator abilities to adjust examples and you might beat me ;-))

          1 Reply Last reply Reply Quote 2
          • PeterJonesP
            PeterJones @PeterJones
            last edited by

            @Terry-R ,

            So I assumed there will likely be a bit of to and fro before OP becomes happy. My solution at least will let them know it’s possible and they need to sort out proper examples!

            Good point. But since I wrote what follows, I’ll at least present it as the best starting point for the user

            @PeterJones said in Help.. how to...:

            I think a hopefully-small tweak to yours would bring it in to working, without getting as complicated as mine.

            FIND = (?<![\r\n])\R(?!=\d+-|[ABCD]\)|\R) – adds a check to make sure that the previous line wasn’t also a newline and that the next line after the matched line isn’t a newline (thus allowing spaces between questions and answers)

            From my data above, this slight tweak to @Terry-R’s regex gives
            NEXT TRY:

            Question:
            
            1- This question originally spread across multiple lines?:
            
            
            A) This answer also started as two lines
            B) To Be or Not To Be
            C) I am not right
            D) Don't even think of guessing D
            
            ...
            
            9- Short Question
            
            A) Short Answer
            B) Be Short
            C) See, I am short
            D) Done
            
            13- Another question originally spread across multiple lines?:
            
            
            A) Apples
            B) Not the answer, but spread across multiple lines
            C) Cats!
            D) Dogs. Run away, run away!
            

            … which I think is a reasonable merging of the data. And if there are some questions/answers spread over three or more lines, just run the regex more than once, until nothing changes.

            1 Reply Last reply Reply Quote 1
            • Un KnownU
              Un Known
              last edited by

              First of all sorry for all the mistakes… reading the answers it seems the leaving spaces where there where supposed not to be and not using words, made things difficult.

              Sorry… As i said English is not my mother tongue.

              Example 1

              1- What’s your
              name?:

              A) Juan
              B) Pedro de
              la Fuente Rodriguez
              C) Oscar
              D) Alfredo

              What I want:

              1- What’s your name?:

              A) Juan
              B) Pedro de la Fuente Rodriguez
              C) Oscar
              D) Alfredo

              Sorry again, I supposed that you will guess that my mistakes where from just not being meticulous while writing… my bad.

              I assume Terry’s answers is the correct one, thanks. I will try that.

              Terry RT 1 Reply Last reply Reply Quote 0
              • Terry RT
                Terry R @Un Known
                last edited by

                @Un-Known said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):

                I assume Terry’s answers is the correct one, thanks. I will try that.

                We don’t want you to assume. Try both and see what each does to your data, make sure you work on a copy of the document! Because you didn’t give us real data (a common issue we have when trying to help) it’s often a guessing game and will often take several posts both by yourself and the solution provider to get one that works for you.

                Terry

                Un KnownU 1 Reply Last reply Reply Quote 0
                • Un KnownU
                  Un Known
                  last edited by

                  notepad++forum.png

                  As you can see the problem I have using Terry’s solution is that questions and the correct answer are in the same line.

                  I will try to post this better. I did it bad. Sorry.

                  Example:

                  1- What’s your
                  name?:

                  A) Juan
                  B) Pedro de
                  la Fuente Rodriguez
                  C) Oscar
                  D) Alfredo
                  ANSWER: D

                  What I want:

                  1- What’s your name?:

                  A) Juan
                  B) Pedro de la Fuente Rodriguez
                  C) Oscar
                  D) Alfredo
                  ANSWER: D

                  Sorry I omitid things like the field ANSWER because when i was talking about Moodle in the Aiken format I supposed people would know beforehand… Really sorry for not explaining things in the correct way. Really, sorry.

                  PeterJonesP 1 Reply Last reply Reply Quote 0
                  • Un KnownU
                    Un Known @Terry R
                    last edited by

                    Terry

                    Really sorry. I know now that i did it bad.

                    1 Reply Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @Un Known
                      last edited by PeterJones

                      @Un-Known said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):

                      As you can see the problem I have using Terry’s solution is that questions and the correct answer are in the same line.

                      That’s what I tried to tell you in my follow-on posts.

                      But now that you’ve also told us that a line starting with ANSWER is also in the data, my previous suggestion will need to be tweaked.

                      Please try this suggestion:
                      FIND WHAT = (?<![\r\n])\R(?!=\d+-|[ABCD]\)|ANSWER|\R)
                      REPLACE WITH = \x20 (or you could type a space character in the REPLACE WITH box).

                      I believe that will work for you. (At least, it does with your most recent data)

                      Un KnownU 1 Reply Last reply Reply Quote 2
                      • Un KnownU
                        Un Known @PeterJones
                        last edited by

                        Peter jones

                        THANK YOU SO MUCH!!! that worked!

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors