eclipse 如何在eclipse中搜索回车
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1391415/
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
How to search for carriage return in eclipse
提问by zfranciscus
If I have the following text in my Eclipse editor:
如果我的 Eclipse 编辑器中有以下文本:
Text Line 1
Text Line 2
I would like to concatenate the text into:
我想将文本连接成:
Text Line 1Text Line 2
My first idea was to search for carriage return character '\n' and replace it with '' to concatenate it.
我的第一个想法是搜索回车符 '\n' 并将其替换为 '' 以连接它。
I tried using the search function of Eclipse, but it does not recognize carriage return character.
我尝试使用Eclipse的搜索功能,但它不识别回车符。
Are there any other editor that can do this?
有没有其他编辑器可以做到这一点?
回答by soru
Eclipse does this if you:
如果您执行以下操作,Eclipse 会执行此操作:
- turn on regular expression mode in search/replace
- enter \R for the newline
- 在搜索/替换中打开正则表达式模式
- 输入 \R 作为换行符
回答by Johannes Weiss
Just use Edit -> Find/Replace
, switch on the Regular Expressions
checkbox, search for \n
and replace it by space.
只需使用Edit -> Find/Replace
,打开Regular Expressions
复选框,搜索\n
并用空格替换它。
I tried it in Eclipse 3.4 and it worked well.
我在 Eclipse 3.4 中尝试过,效果很好。
回答by Stefan
Short answer:
简短的回答:
I decided to use \s++
as separator in multi-line search expressions (with regular expressions enabled) and \Qfoo\E
to escape special characters if required.
我决定\s++
在多行搜索表达式中用作分隔符(启用正则表达式)并\Qfoo\E
在需要时转义特殊字符。
Long answer:
长答案:
As soru
already answered, for any "Unicode linebreak sequence" a regular expression search with \R
can be used.
正如soru
已经回答的那样,对于任何“Unicode 换行符序列”,\R
都可以使用正则表达式搜索。
A pure carriage return is represented by \r
. Upper and lower case make a difference. \R represents any unicode linebreak sequence (for example \r\n).
纯回车由 表示\r
。大小写有所不同。\R 表示任何 Unicode 换行符序列(例如 \r\n)。
I found this SO question because I wanted to search for a multi-line expression in Eclipse, including line breaks and tabs:
我发现了这个问题,因为我想在 Eclipse 中搜索多行表达式,包括换行符和制表符:
@Override
@Transient
In order to include the white spaces in my regular search expression I used (on Windows platform)
为了在我使用的常规搜索表达式中包含空格(在 Windows 平台上)
@Override\r\n\t*@Transient
Following expressions also work:
以下表达式也有效:
@Override\R\t*@Transient
@Override\s++@Transient
@Override\R\t*@Transient
@Override\s++@Transient
Please notethat the second expression also matches @Override @Transient
without a line break, which is fine for me.
请注意,第二个表达式也匹配@Override @Transient
而没有换行符,这对我来说很好。
Following expressions did not! work for me:
下面的表情没有!对我来说有效:
@Override\r\t*@Transient
@Override\n\t*@Transient
@Override\r\t*@Transient
@Override\n\t*@Transient
Explanation of some regular expressions:
一些正则表达式的解释:
\R
represents any unicode linebreak sequence (for example\r\n
)\s
represents any white space\t
represents a tab*
matches zero or more occurrences++
matches one ore more occurrences\Q
and\E
escape wrapped content. Use them if your original multi line expression includes special regex characters, for example
\R
表示任何 unicode 换行符序列(例如\r\n
)\s
代表任何空白\t
代表一个选项卡*
匹配零次或多次出现++
匹配一个或多个出现\Q
并\E
转义包装的内容。例如,如果您的原始多行表达式包含特殊的正则表达式字符,请使用它们
\Q/**\E\s++\Q*\E
\Q/**\E\s++\Q*\E
matches
火柴
/**
*
Also see:
另见:
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
回答by Noon Silk
Most find and replace tasks in editors (at least, TextPad) have the ability to replace via a regex. If you can find this option in eclipse, then just use that.
编辑器中的大多数查找和替换任务(至少是 TextPad)都能够通过正则表达式进行替换。如果你可以在 eclipse 中找到这个选项,那么就使用它。
回答by RoutesMaps.com
\r is the correct regular expression for carriage return. But Eclipse standard editor does not find it. So use external editor, for example notepad++
\r 是正确的回车正则表达式。但是 Eclipse 标准编辑器没有找到它。所以使用外部编辑器,例如记事本++