Aron
Aron

Reputation: 29

Regular expression to align text

I'm new here. I was seeking for some help to get the following done with regex.

I have a MC tests lines like this:

Q1  I.......go to see the doctor last week because I was very ill.  
(a) must (b) must to    (c) had to (d) should to
Q2  I could.......bought that car but I didn't have enough money to pay for the petrol. 
(a) had (b) have    (c) have to (d) can

I would like the line from horizontal to vertical. That's it. It should look like this.

Q1  I.......go to see the doctor last week because I was very ill.  
(a) must
(b) must to
(c) had to
(d) should to

Q2  I could.......bought that car but I didn't have enough money to pay for the petrol. 
(a) had
(b) have
(c) have to
(d) can

I can't seem to make it work. That would save me long long hours of work. Any help is appreciated.

Upvotes: 1

Views: 1897

Answers (1)

Jcl
Jcl

Reputation: 28272

Find:

(\([b-d]\))

* this is for a-d answers, change d for the maximum possible answer

Replace with:

\r\n$1

Input:

Q1  I.......go to see the doctor last week because I was very ill.  
(a) must (b) must to    (c) had to (d) should to
Q2  I could.......bought that car but I didn't have enough money to pay for the petrol. 
(a) had (b) have    (c) have to (d) can

Output:

Q1  I.......go to see the doctor last week because I was very ill.  
(a) must 
(b) must to    
(c) had to 
(d) should to
Q2  I could.......bought that car but I didn't have enough money to pay for the petrol. 
(a) had 
(b) have    
(c) have to 
(d) can

Is this enough?

If you want to separate questions with newlines, you can also search for: ^Q(?!1\b)(\d*)\b and replace with \r\nQ$1. That will insert a newline before all questions except for #1

Upvotes: 2

Related Questions