gpt4 book ai didi

regex - Notepad++ 组替换使用\k

转载 作者:行者123 更新时间:2023-12-02 02:43:01 25 4
gpt4 key购买 nike

如何在 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

我在这里做错了什么?

最佳答案

我制定了一个解决方案,以防有人尝试做类似的事情。

选择集合

(^(?'number'^\d{0,4})\t(.*$)(\n\k<number>(.*))*)

最初发布的代码之间的区别是整个代码周围的()

替换为 \1\n 以创建以下格式的集合:

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

选择单独的行
(^(?'number'^\d{0,4})\t(.*$))\n

替换为\3(\3后两个空格)创建

Continuous  Horizontal mattress  Interrupted  Vertical mattress  No use sutures because the immediate denture acts as a stint   
1-5 years 6-10 years 11-15 years 16-20 years 21-25 years
Artery
Vitality of the tooth pulp Age of the patient Absence of root resorption

我不知道如何使用正则表达式将问题 #s 添加回去,但如果需要,可以轻松地将其导入 excel 中以执行此操作。

关于regex - Notepad++ 组替换使用\k,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58020045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com