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

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

eclipse search - regex finding start/end of file with carriage return

regexeclipsesearch

提问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 \Ato represent the start of the file, and \Zto represent the end of the file.

可以用\A来表示文件的开始,也可以用来表示文件\Z的结尾。

回答by Bart Kiers

It seems by default, the multi-line flag mis enabled in Eclipse, causing ^and $to match start- and end-of-lines. You can disable the mflag 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+$)