文本编辑器中的正则表达式转换或文本替换

Regex Transform or Text Replace in Text Editor

我正在尝试在文本编辑器中进行高级文本搜索和替换(我可以使用 SublimeText 或 VSCode)

输入:

parameters['myParameter1']
parameters['myParameter2']

预期输出:

myParameter1
myParameter2

我的文件中有数百个类似的场景。所以这就是为什么我正在考虑使用正则表达式来解决这个问题。

谢谢

VSCode可以搜索一个目录下的所有文件,而且还支持RegExp!

使用 ctrl+shift+f 搜索所有文件,点击 .* 图标获取 RegExp。
</code> 替换 <code>parameters['(.*)'] 之类的搜索表达式应该可以工作!

查看官方指南了解更多信息:VSCode Basic Editing

希望这对您有所帮助。

Regex demo

正则表达式搜索: parameters\['([^']+)'\]

1. parameters\[' this will match parameters[' Optinally if you have other keywords then parameters and which can be dynamic for that you can use [a-zA-Z]+ this will include all lower case and upper case.

2. ([^']+) this will match all except ', () will capture first match in </code>.</p> <p><strong>3.</strong> <code>'\] this will match ending ']

替换: </code></p> <blockquote> <p><strong>Note:</strong> If you are using <code>gedit ubuntu you have to replace it with