0

I have a question in notepad++ like this;

123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

I want the above question to be made in a single line. all the questions will start with answer choice "a". As there are more than 100 questions CTRL+J would be very difficult to apply on every question.

Need Your suggestion please.

0

You can use this expression:

  • find what: \r\n(?!(\d{3}|[a-z])\.? )
    (depending on your OS you might need to remove \r)
  • replace to: "" (nothing)
  • make sure "regular expression" is checked

This works whether you have a dot after the letter ("c.") or not ("a")

Test is here: https://regex101.com/r/4WKuA9/2

enter image description here

  • This will not work if you have multiple blocks. It will join the last answer and the first line of the next question. – Toto Sep 12 at 9:01
  • Hi Mate Juhasz, Thanks for your suggestion. It absolutely works... Awsome!...... But a small issue.... It merges the next question with the last option of the last qustion. In my question I am not using question numbers (as Q. No. 123 in the example given). The result looks like "d. we will risk and land 123. The airplane will not land in time.........." Any suggestion to break the next question? – Rajkumar Janarthanan Sep 15 at 13:24
  • Exactly as Toto told... It joins the last answer and the first line of the next question. – Rajkumar Janarthanan Sep 15 at 13:26
  • Hi Juhasz, Your solution gives me 99% result but for the small issue as said above It joins the last answer and the first line of the next question. A small refinement in the regex would help me to get 100% expected result. Any modifications you can suggest, please. – Rajkumar Janarthanan Sep 15 at 17:41
  • @RajkumarJanarthanan: I've updated the expression, it works with multiple blocks now. – Máté Juhász Sep 16 at 7:05
3
  • Ctrl+H
  • Find what: (?:^\d+\.|\G).+\K\R(?!^[a-z]\.?\h)
  • Replace with: A SPACE
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?:             # start non capture group
  ^             # beginning of line
    \d+         # 1 or more digits
    \.          # a dot
  |             # OR
    \G          # restart from last match position
)               # end group
.+              # 1 or more any character but newline
\K              # forget all we have seen until this position
\R              # any kind of linebreak (i.e. \r, \n, \r\n)
(?!             # neagative lookahead, zero-length assertion that makes sure we haven't after: 
  ^             # beginning of line
    [a-z]       # a small letter
    \.?         # an optional dot
    \h          # 1 horizontal space
)

Given:

123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land
123. The airplane will not land in time
if weather is not clear due to rain and storm. Are you acceptable to re
turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

Result for given example:

123. The airplane will not land in time if weather is not clear due to rain and storm. Are you acceptable to re turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land
123. The airplane will not land in time if weather is not clear due to rain and storm. Are you acceptable to re turn the flight? (the question is splitted into 2 or 3 lines)
a yes
b no
c. yes but refund money
d. we will risk and land

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

  • This is awsome.... A biggggggggg..... thanks to you. I was struggling to get this.... Excellent... Thanks. – Rajkumar Janarthanan Sep 14 at 5:04
  • @RajkumarJanarthanan: You're welcome, glad it helps. But why did you unmark my answer and prefer the other one that doesn't work? – Toto Sep 15 at 19:02
  • Hi Toto, Excuse me for unmarking it... your solution is really great. But a small issue is it was not merging lines, in between two questions i.e. if an answer of particular choice of a or b runs for two or three lines, whereas in other case it merges that too... However, in both the cases there are small issues need to be refined. I wanted to mark both but unfortunately I can mark only one. Im sorry to do that. – Rajkumar Janarthanan Sep 16 at 1:05
  • 1
    @Toto, All I could do it upvote your answer and give you an honest appreciation! Good work – Prasanna Sep 16 at 8:19
  • @Prasanna: Thank you. – Toto Sep 16 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.