I have text file with bunch of multiple choices questions.
The questions format needs to be single lines
like this
Question
A.
B.
C.
However i found some questions containing multiple lines
like this
Question
question second line.
A.
B.
C.
Is it possible to auto join all the lines of the questions?
to be
Question question second line.
A.
B.
C.
Not all questions having multiple lines, however all questions are followed by the same numbering which is
A.
B.
C.
Thanks in advance
3 Answers
- Ctrl+H
- Find what:
^(?![A-Z]\.).+\K\R(?![A-Z]\.) - Replace with: 1 blank space
- CHECK Match case
- CHECK Wrap around
- CHECK Regular expression
- UNCHECK
. matches newline - Replace all
Explanation:
^ # beginning of line
(?![A-Z]\.) # negative lookahead, make sure the line doesn't begin with a capital and a dot
.+ # 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)
(?![A-Z]\.) # negative lookahead, make sure the following line doesn't begin with a capital and a dotScreenshot (before):
Screenshot (after):
Do this:
Find what: ^([^\r\n]+)\r\n([^\r\n]+)\r\nA.
Replace with: \1 \2\r\nA.
Where [^\r\n] is any character which is not an end of line.
Place a check-mark next to "Regular expression" and ". matches newline".
Assuming that Question and A, B, C bullets are case-sensitive, then you can use a negative-lookahead group regular expression search and replace.
For example:
- Bring-up Notepad++ Search and Replace dialog by pressing [Ctrl]+H, or Search menu > Replace...
- Find what:
\r\n(?!Question|A\.|B\.|C\.) - Replace with: <-- space
- Search option: Match case + Wrap around
- Search mode: Regular expression
Essentially, the regular expression above indicates replace any CR/LF that does not appear before Question, A., B., or C. with a space character -- effectively moving incorrectly word-wrapped lines up to the Question line.
1