eclipse 搜索 - 正则表达式用回车符查找文件的开始/结束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6832525/
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
eclipse search - regex finding start/end of file with carriage return
提问by Mike Henke
I would like to remove any line breaks/carriage returns at the start and end of files but eclipse doesn't seem to recognize $$
or ^^
for end/start of file. Anyone know how to do a regex with eclipse search?
我想删除文件时的开始和结束的任何换行符/回车但是Eclipse似乎并没有认识到$$
或^^
最终/文件的开始。任何人都知道如何使用 eclipse 搜索进行正则表达式?
sof ^^ Start of File
eof $$ End of File
回答by Samir Talwar
You can use \A
to represent the start of the file, and \Z
to represent the end of the file.
可以用\A
来表示文件的开始,也可以用来表示文件\Z
的结尾。
回答by Bart Kiers
It seems by default, the multi-line flag m
is enabled in Eclipse, causing ^
and $
to match start- and end-of-lines. You can disable the m
flag by adding (?-m)
in front of your regex.
似乎默认情况下,多行标志m
在 Eclipse 中启用,导致^
并$
匹配行首和行尾。您可以m
通过(?-m)
在正则表达式前面添加来禁用该标志。
I just tested it, and it only removes line breaks at the start or end of the file:
我刚刚测试了它,它只删除文件开头或结尾的换行符:
(?-m)(^\s+|\s+$)