简体   繁体   English

在notepad ++或Visual Studio编辑器中使用正则表达式可以将多行替换为自动递增数吗?

[英]Do the regular expression in notepad++ or Visual Studio editor can replace multi-line to auto increment number?

for instance, change the following(multi-line): 例如,更改以下(多行):

hello-a
hello-b
hello-c
hello-d

to

hello-1
hello-2
hello-3
hello-4

I just find regex "hello-[a-zA-Z]*" to match "hello-?", but can't find a replacement replace them to auto-added numbers. 我只是找到正则表达式“hello- [a-zA-Z] *”以匹配“hello-?”,但找不到替代品将它们替换为自动添加的数字。

I'm not yet sure about Notepad++ , but for Textpad , you use: 我还不确定 Notepad++ ,但 对于Textpad ,你使用:

\i(n)    -or-
\i(n,)   -or-
\i(n,m)

in your case \\i(1) or just \\i . 在你的情况下\\i(1)或只是\\i

Also, in the example regex you provided: 此外,在您提供的示例正则表达式中:
hello-[a-zA-Z]*

It would match (as you have mentioned): 它会匹配(正如你所提到的):

hello-a
hello-b
hello-c
hello-d

but it would also match "hello-a...a" ("hello-" followed by one or more alpha): 但它也会匹配“hello-a ... a”(“hello-”后跟一个或多个alpha):

hello-aa
hello-abc
hello-tuvwxyz

and it would also match "hello-" (when followed by nothing or followed by non-alpha): 并且它也会匹配“hello-”(当后面没有任何内容或后面跟着非alpha):

hello-
hello-#
hello-1

So, if this is as you intended it, the Regex search would be: 所以,如果这是你想要的那样,正则表达式搜索将是:

(hello-)[a-zA-Z]*

If you want to match "hello-" followed only-one alpha, the Regex search would be: 如果你想匹配“hello-”只跟着一个alpha,那么Regex搜索将是:

(hello-)[a-zA-Z]

If you want to match "hello-" followed one-or-more alpha, the Regex search would be: 如果你想匹配“hello-”跟随一个或多个alpha,正则表达式搜索将是:

(hello-)[a-zA-Z]+

For all these, the Regex replacement would be: 对于所有这些,正则表达式替换将是:

\1\i(1)




The basic syntax is: 基本语法是:

\i(100,5) --> 100,105,110...

n is the starting point, and m is the increment amount. n是起点,m是增量。

\i --> 1,2,3...

If parenthesis are not specified (\\i by itself), this is the same as \\i(1) or \\i(1,1) 如果未指定括号(\\ i本身),则与\\ i(1)或\\ i(1,1)相同

 \\i --> 1,2,3... 

If parenthesis are specified... 如果指定了括号......

If n is omitted then n defaults to 0. 如果省略n则n默认为0。

\i(1) --> 1,2,3...
\i(101) --> 101,102,103...

If ",m" is omitted, then m defaults to 1. 如果省略“,m”,则m默认为1。

\i() --> 0,1,2...

If both n and m are omitted [\\i() by itself], this is the same as \\i(0) or \\i(0,1) 如果n和m都省略[\\ i()本身],则与\\ i(0)或\\ i(0,1)相同

 \\i() --> 0,1,2... 

Note: in order for \\i to work properly, you have to Replace all on the entire document (or the entire selection). 注意:为了使\\i正常工作,您必须在整个文档(或整个选择)上全部Replace all

There is no ending parameter. 没有ending参数。 \\i will keep incrementing the replacement until all matches have been replaced. \\i将继续增加替换,直到所有比赛都被替换。



It appears this is not supported in Notepad++ . 看起来这在Notepad++是不受支持的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM