使用正则表达式进行搜索和替换
在Search Results 视图中使用正则表达式搜索和替换文件。
Qt Creator 中使用的正则表达式以 Perl 正则表达式为蓝本。有关使用正则表达式的更多信息,请参阅QRegularExpression 。
例如,用函数 (foo.equals(bar)
) 替换相等检查 (foo == bar
):
- 将更改提交到版本控制中,因为无法撤销替换操作。
- 按Ctrl+Shift+F或转到Edit >Find/Replace >Advanced Find >Open Advanced Find 打开Search Results 。
- 在Scope 中,选择适合您搜索的内容。
- 选择Use regular expressions 。
- 在Search for 中输入以下文本:
if \((.*) == (.*)\)
- 选择Search & Replace ,查看搜索结果列表。
- 在Replace with 中,输入以下文本:
if (\1.strictlyEquals(\2))
- 选择Replace 以替换文本的所有实例。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.