问题描述
我试图找出一种方法,用一个大于1的数字替换文本文件中的字符串。我试图将几行变成这样:
I am trying to figure out a way to replace a string in a text file by a number that increments by more than 1. I am trying to turn a couple of lines like this:
result_A_in_S1-S2.txt
result_A_in_S1-S2.txt
result_A_in_S1-S2.txt
result_A_in_S1-S2.txt
到 S1
和 S2
。
result_A_in_1000-1003.txt
result_A_in_1004-1007.txt
result_A_in_1008-1011.txt
result_A_in_1012-1015.txt
我想要知道我是否可以使用replace regexp定义一个字符串,然后将该字符串替换为某个起始编号,并在找到下一个出现的字符串时,将其替换为起始编号+选择的增量。
I want to know if I can define a string with replace regexp and then have that string be replaced with some starting number, and as it finds the next occurrence of string, it replaces with starting number + chosen increment.
我现在才开始学习Emacs,并且对它不熟悉。
I am just now starting learn Emacs and am pretty unfamiliar with it.
推荐答案
是的,您可以通过[query-] replace-re做到这一点通过评估替换中的elisp并利用从零开始的替换计数器 \#
在Emacs中进行gexp。例如:
Yes, you can do that with [query-]replace-regexp in Emacs, by evaluating elisp in your replacement, and utilising the zero-based replacement counter \#
. e.g.:
query-regexp-replace
S1-S2
\,(let((start(+ 1000(* 4 \#)))))(格式%d-%d start(+ start 3)))
这篇关于Emacs用增量序列替换regexp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!