我正在寻找一种方法来替换表单的所有实例:
model->variable
其中
models[variable][index]
变量几乎可以是字母和数字的任意组合,可能定义为 [0-9a-Z]{4,12}。
文本中有数百个这样的变量。我需要知道找到的字符串“变量”的确切形式才能在替换中使用它。有没有办法“记住”该字符串并在以后使用它?或者任何其他方法/软件在这种情况下可以提供帮助?
提前致谢。
如果你能顺便将“变量”转换为大写,那就太棒了。
I'm looking for a way to replace all instances of a form:
model->variable
with
models[variable][index]
where variable can be pretty much any combination of letters and numbers, probably defined like [0-9a-Z]{4,12}.
There are hundreds of such variables in the text. I need to know exact form of found string "variable" to use it in replacement. Is there a way to "remember" the string and use it later? Or any other method / software which could help in such case?
Thanks in advance.
If you could convert "variable" to uppercase by the way, it would be awesome.
发布评论
评论(1)
如果将模式括在
\(...\)
中,则可以使用模式中的内容进行替换。然后,您可以使用\1
插入第一个此类括号捕获的内容。解决您的问题的一个简单的解决方案是:
You can use things in the pattern to replace with if you enclose it in
\(...\)
. You then use\1
to insert the thing that was captured by the first such bracket.A naïve solution to your problem would be this: