匹配非空行中的换行符,而不是前面的某些字符

时间:2016-02-10 12:44:47

标签: regex replace newline

我尝试使用正则表达式(?<=^(?![ \t]*@).+)(?<![\{\};:)]|//.{0,1024}|^[ \t]+)\R来:

  • 匹配换行符而不匹配前面的字符
  • 不匹配空间行(空行)中的换行符
  • 不匹配由可选空格(不是换行符)和符号'@'开头的行中的换行符。
  • 不匹配包含[unescaped]'//'的行中的换行符。
  • 不匹配前缀为'{','}',';'的换行符要么 ':'。 (如果不匹配以可选空格和该字符开头的换行符,则更好。)

该正则表达式在Eclipse搜索中有效,但我无法替换匹配,因为Eclipse发现并替换了错误。然后我在Notepad++TextPad中尝试了它,但他们告诉我正则表达式格式不正确。我尝试在在线regexp验证器中验证正则表达式,并说我正则表达式有错误。

如何构建满足所列要求的正确正则表达式?

has to match the new line.
    has to match the new line.
has to match the new line
doesn't have to match the new line;
    doesn't have match the new line     {
doesn't have to match the new line}
doesn't have to match the new line:
doesn't have to match the new line //because of this
@doesn't have to match the new line
h@s to match the new line-

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此正则表达式^[^@]+[ ]*.*[ ]*([^;{}:]+)[ ]*$

它将涵盖除了一个

以外的所有情况
  

不必匹配新行//因为这个