首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用\k的记事本++组替换

使用\k的记事本++组替换
EN

Stack Overflow用户
提问于 2019-09-19 23:42:04
回答 1查看 206关注 0票数 3

如何使用Notepad++中的正则表达式将属于一组的所有项放在一行中?

我有一套练习问题的答案,其格式如下:

代码语言:javascript
复制
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

我希望对结果进行格式化,使每一组都在一行上:

代码语言:javascript
复制
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

我编写了以下regex来选择这些集合:

代码语言:javascript
复制
^(?'number'^\d{0,4})\t(.*$)(\n\k<number>(.*))*

\1 \2 \4给出

代码语言:javascript
复制
29 Continuous   No use sutures because the immediate denture acts as a stint
30 1-5 years    21-25 years
31 Artery 

我在这里做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-21 17:29:37

我想出了一个解决办法,以防有人试图做类似的事情。

选择具有

代码语言:javascript
复制
(^(?'number'^\d{0,4})\t(.*$)(\n\k<number>(.*))*)

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

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

代码语言:javascript
复制
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

选择单独的行

代码语言:javascript
复制
(^(?'number'^\d{0,4})\t(.*$))\n

\3替换(\3之后的两个空格)来创建

代码语言:javascript
复制
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

我不知道如何使用regex返回问题#s,但是如果需要的话,它可以很容易地导入到excel中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58020045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档