正则表达式以对齐文本

时间:2016-04-19 06:38:11

标签: regex notepad++

我是新来的。我正在寻求一些帮助,以便使用正则表达式完成以下操作。

我有一个像这样的MC测试线:

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

我想从水平线到垂直线。就是这样。它看起来应该是这样的。

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

我似乎无法使其发挥作用。这将节省我长时间的工作。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

查找

(\([b-d]\))

* 这是针对a-d的答案,更改d以获得最大可能答案

替换为:

\r\n$1

输入:

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

输出:

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

这够了吗?

如果您想使用换行符分隔问题,您还可以搜索:^Q(?!1\b)(\d*)\b并替换为\r\nQ$1。除了#1

之外,这将在所有问题之前插入换行符