eclipse 如何删除与模式匹配的整行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3725469/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:06:38  来源:igfitidea点击:

How to remove an entire line which matches a pattern

regexeclipsereplace

提问by Joe

The following pattern matches an entire line, how do I search and removethese lines. If I leave a space in the replace string, it leaves a blank in that particular line, when I do via eclipse.

以下模式匹配整行,如何搜索和删除这些行。如果我在替换字符串中留下一个空格,当我通过 eclipse 执行时,它会在该特定行中留下一个空白。

^[\t ]*<param name="logic" .*$

回答by El Ronnoco

I don't know anything about eclipse but you may need to include the \nnewline match in order to remove the line completely. Also - is it possible to replace with an empty string as opposed to a space?

我对 eclipse 一无所知,但您可能需要包含\n换行符匹配才能完全删除该行。另外 - 是否可以替换为空字符串而不是空格?

^[\t ]*<param name="logic" .*\n$

回答by Simon D.

To delete the line, you must also remove the line-break, not only the contents of the line. So your Expression should end with \r\n instead of $. Can't try it at the moment, so you will have to experiment yourself for the correct syntax.

要删除该行,您还必须删除换行符,而不仅仅是该行的内容。所以你的表达式应该以 \r\n 而不是 $ 结尾。目前无法尝试,因此您必须自己试验正确的语法。