Notepad++ 可以将匹配正则表达式的字符串转换为小写吗? [英] Can Notepad++ convert strings matched regular expression to lowercase?
问题描述
我有一个 C++ 源文件,它使用 getMemberName() 形式的函数返回成员数据.相反,我想使用 memberName().
I have a C++ source file that uses functions of the form getMemberName() to return member data. Instead, I'd like to use memberName().
为了匹配需要更改的函数名称实例,我使用了以下正则表达式:
In order to match instances of function names that need to change, I'm using the following regular expression:
(\s+)get([A-Z])
问题是,我不知道如何用小写版本替换 \2 的实例.有没有人有任何想法,或者我应该诉诸编写 Perl 脚本?
The problem is, I don't know how to replace the instance of \2 with its lowercase version. Does anyone have any ideas, or should I resort to writing a Perl script?
谢谢,
扎克
推荐答案
注意:此功能可通过 \L\1\E
正则表达式替换模式在 Notepad++ 中使用.
Note: This feature is available in Notepad++ via the \L\1\E
regex substitution pattern.
\L
小写\2
用于匹配组 2\E
关闭小写,以防您有任何进一步的替换.
\L
lowercase on\2
for matching group 2\E
lowercase off, in case you have any further replacements.
像往常一样,还有另一种方式.这可以在 Notepad++ 中使用 PythonScript 插件来完成,以及其他任何超出范围的东西无需编写完整插件即可在记事本++中使用.
There is, as usual, another way. This can be done in Notepad++ with the PythonScript plugin, as well as anything else a little beyond the scope of what's available in notepad++ without having to write a full plugin.
首先在Notepad++中安装PythonScript插件
First, install the PythonScript plugin in Notepad++
插件 >插件管理器显示插件管理器
Plugins > Plugin Manager > Show Plugin Manager
检查Python 脚本";在可用"中选项卡并单击安装"然后重启记事本++
Check "Python Script" in the "Available" tab and click "Install" then restart Notepad++
然后设置一个 Python 脚本
Then setup a Python script
插件 >Python 脚本 >新脚本
Plugins > Python Script > New Script
给它一个有用的名字
添加以下代码
# Start a sequence of actions that is undone and redone as a unit. May be nested.
editor.beginUndoAction()
# trimFunctionName - for editor.pysearch
def trimFunctionName( index, match ):
editor.pyreplace( match.re, match.group(1) + match.group(2).lower(), 1, 0, index, index )
# I couldn't work out how to jam the .lower call into a editor.pyreplace()
# so used editor.pysearch() to check the regex and run a function with match
# information
editor.pysearch(r'(\s+)get([A-Z])', trimFunctionName )
# end the undo sequence
editor.endUndoAction()
然后运行脚本.
插件 >Python 脚本 >脚本 >你的脚本"
Plugins > Python Script > Scripts > "yourScript"
您可以提示用户输入或执行许多其他操作来scintilla 使用提供的对象
You can prompt for user input or do a myriad of other things to scintilla with the provided objects
这篇关于Notepad++ 可以将匹配正则表达式的字符串转换为小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!