• Login
Community
  • Login

Align Questions in One line.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 1.0k 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.
  • M
    Martin Martin
    last edited by Jan 26, 2024, 1:56 PM

    Hi everyone… hope you can help me. Apologies for my English.

    I got like 1800 questions. Like this:

    Notepad++.png

    As you can see question 295 is in one single line. But question 296 es in two lines. I have a lot of questions like that, like 296. I need all the questions to be in one single line. how can i achieve that?

    Thanks.

    A 1 Reply Last reply Jan 26, 2024, 2:23 PM Reply Quote 0
    • A
      Alan Kilborn @Martin Martin
      last edited by Jan 26, 2024, 2:23 PM

      @Martin-Martin

      You could use this as a starting point:

      Find: (?-s)^\d+\..+\K\R(?!A\))
      Replace: a single space
      Search mode: Regular expression

      M 2 Replies Last reply Jan 26, 2024, 2:49 PM Reply Quote 2
      • M
        Martin Martin @Alan Kilborn
        last edited by Jan 26, 2024, 2:49 PM

        @Alan-Kilborn said in Align Questions in One line.:

        Find: (?-s)^\d+…+\K\R(?!A))
        Replace: a single space
        Search mode: Regular expression

        THANKS A LOT!!! BIG THANKS!!!

        That solved my problem!!!

        1 Reply Last reply Reply Quote 1
        • M
          Martin Martin @Alan Kilborn
          last edited by Jan 26, 2024, 8:05 PM

          @Alan-Kilborn

          Sorry to bother you again… did you know how to do the same, but for the Answers?

          I mean… I have this format:

          A) XXXXXXXXX
          XXXXXX
          B)XXXXXXXX
          C)XXXXXXXX
          D)XXXXXX
          XXXXXXXX

          I want A and B or whatever answers in the exam to be in 1 line too, like this:

          A)XXXXXX
          B)XXXXX
          C)XXXXXXXXX
          D)XXXXXXXX

          P 1 Reply Last reply Jan 26, 2024, 8:17 PM Reply Quote 0
          • P
            PeterJones @Martin Martin
            last edited by PeterJones Jan 26, 2024, 8:17 PM Jan 26, 2024, 8:17 PM

            @Martin-Martin said in Align Questions in One line.:

            did you know how to do the same, but for the Answers?

            In the regex that @Alan-Kilborn showed, the \d+\. at the beginning means “one or more digits followed by a literal dot character”.

            For requiring it to be one or more letters then an end-parentheses like your answers are, replace that portion of the regex with a regex that means “one or more uppercase letters followed by a literal parentheses”: \u+\) …

            Further, the (?!A\)) says “stop the match once you hit a literal A)” … So the equivalent for the answer would be "stop the match once you hit a different capital(s)-then-paren, and stop if you come across ANSWER: -> (?!\h+\))(?!ANSWER:)

            Those tweaks to the original will work for your new

            ----

            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
            M 1 Reply Last reply Jan 26, 2024, 8:24 PM Reply Quote 0
            • M
              Martin Martin @PeterJones
              last edited by Martin Martin Jan 26, 2024, 8:30 PM Jan 26, 2024, 8:24 PM

              @PeterJones said in Align Questions in One line.:

              (?!\h+))(?!ANSWER:)

              Sorry I’m new to this. English is not my mother tongue.

              I understood this?:

              Find: (?-s)^\u+…+\K\R(?!\h+))(?!ANSWER:))
              Replace: a single space
              Search mode: Regular expression

              Obviously I did something wrong because it says Invalid Regular Expression.

              I managed to erase some parenthesis but the result was that B options and C options dissapeared or merged in one line… I’m a complete disaster. but i managed to undo actions. Everything is fine, answers are back, but I can’t put them in one line yet.

              P 1 Reply Last reply Jan 26, 2024, 8:51 PM Reply Quote 0
              • P
                PeterJones @Martin Martin
                last edited by PeterJones Jan 26, 2024, 8:51 PM Jan 26, 2024, 8:51 PM

                @Martin-Martin ,

                You misunderstood on one (the … wasn’t part of the expression: it wasn’t red), and I had a couple of typos (accidentally said \h+ instead of \u+).

                I guess I should have spelled it all out, and should have tried it before posting.

                FIND WHAT: (?-s)^\u+\).+\K\R(?!\u\))(?!ANSWER)

                converts

                1. Question 1
                A) A1
                second line
                B) two
                C) three
                D)four
                with another line
                ANSWER
                2. question two
                A) A1
                second line
                B) two
                C) three
                D)four
                with another line
                ANSWER
                

                to

                1. Question 1
                A) A1 second line
                B) two
                C) three
                D)four with another line
                ANSWER
                2. question two
                A) A1 second line
                B) two
                C) three
                D)four with another line
                ANSWER
                

                And if any of your choices are 3 or more lines long, just re-run the regex until it doesn’t make any more changes.

                M 1 Reply Last reply Jan 26, 2024, 8:58 PM Reply Quote 1
                • M
                  Martin Martin @PeterJones
                  last edited by Jan 26, 2024, 8:58 PM

                  @PeterJones said in Align Questions in One line.:

                  (?-s)^\u+).+\K\R(?!\u))(?!ANSWER)

                  I don’t know how to express gratitude on the internet. But BIG THANKS. YOU SAVED ME A LOT OF TIME.

                  Really. THANK YOU.

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