【发布时间】:2020-01-21 00:30:37
【问题描述】:
如何在 Notepad++ 中使用正则表达式将属于一组的所有项目放在一行上?
我有一组练习题答案,格式如下:
29 Continuous
29 Horizontal mattress
29 Interrupted
29 Vertical mattress
29 No use sutures because the immediate denture acts as a stint
30 1-5 years
30 6-10 years
30 11-15 years
30 16-20 years
30 21-25 years
31 Artery
32 Vitality of the tooth pulp
32 Age of the patient
32 Absence of root resorption
我希望对结果进行格式化,使每组都在一行上:
29 Continuous Horizontal mattress Vertical mattress No use sutures because the immediate denture acts as a stint
30 1-5 years 6-10 years 11-15 years 16-20 years 21-25 years
31 Artery
32 Vitality of the tooth pulp Age of the patient Absence of root resorption
我编写了以下正则表达式来选择集合:
^(?'number'^\d{0,4})\t(.*$)(\n\k<number>(.*))*
用\1 \2 \4 代替
29 Continuous No use sutures because the immediate denture acts as a stint
30 1-5 years 21-25 years
31 Artery
我在这里做错了什么?
【问题讨论】:
-
当您使用应用于组的量词时,仅保留最后一个匹配项。这就是您与可能出现 0 次或多次的第四组一起使用的内容,
-
我在您的正则表达式中看到的一个问题是,您没有在示例文本中使用制表符,而是使用两个空格,在修复此问题后,您的正则表达式匹配,但是您尝试做的事情是不可能的正则表达式。您需要使用 Python 等脚本语言进行一些编程。
标签: regex notepad++ regex-group