Eclipse 的搜索和替换中的匹配组语法是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1095413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the match group syntax in Eclipse's search and replace
提问by OscarRyz
What's the syntax to perform a search/replace on Eclipse and use "match groups" (is that what it's called?)
在 Eclipse 上执行搜索/替换并使用“匹配组”的语法是什么(这就是所谓的?)
On vi I do the following:
在 vi 上,我执行以下操作:
%s/log\(.*\)/log debug/g
And lines like this one:
和这样的行:
log "Message"
are replaced with:
替换为:
log "Message" debug
What's the correct syntax for eclipse in the search/replace dialog box (beside checking up "Regular expressions")
搜索/替换对话框中 eclipse 的正确语法是什么(除了检查“正则表达式”)
Thanks.
谢谢。
回答by Peter Boughton
Use $1 instead of \1
使用 $1 而不是 \1
For the /g global replace flag, use the Replace All button:
对于 /g 全局替换标志,请使用“全部替换”按钮:
(source: bpsite.net)
(来源:bpsite.net)
Note: The above is the Find/Replace dialog for a single file, comes up for Ctrl-F
注意:上面是单个文件的查找/替换对话框,出现在 Ctrl-F
For working across multiple files, default shortcut is Ctrl-H, and the dialogs are a bit different:
对于跨多个文件,默认快捷键是 Ctrl-H,对话框有点不同:
回答by AdamC
In the Find Field: log(.*)
在查找字段中: log(.*)
Int the Replace With Field: log$1 debug
Int the Replace With Field: log$1 debug