在非空行中匹配换行符,并且不以某些字符开头 [英] Match newlines in non empty lines and not preceded by some characters

查看:89
本文介绍了在非空行中匹配换行符,并且不以某些字符开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用regexp (?<=^(?![ \t]*@).+)(?<![\{\};:)]|//.{0,1024}|^[ \t]+)\R进行以下操作:

I tried to use the regexp (?<=^(?![ \t]*@).+)(?<![\{\};:)]|//.{0,1024}|^[ \t]+)\R to:

  • 匹配换行符而不匹配前面的字符
  • 请勿在仅空格行(空行)中匹配换行符
  • 请勿在以可选空格(不是换行符)和符号"@"开头的行中匹配换行符.
  • 在包含[未转义]'//'的行中不匹配换行符.
  • 不匹配以"{",}",;"开头的换行符或者 ':'. (更好的是,如果与换行符之前的可选空格和该字符不匹配).

该正则表达式在Eclipse搜索中有效,但是由于Eclipse查找和替换错误,因此无法替换匹配项.然后,我在 Notepad ++

That regexp worked in Eclipse search, but I cannot replace the match because an Eclipse find-and-replace bug. Then I tried it in Notepad++ and in TextPad, but they told me that the regexp is malformed. I tried to validate the regexp in a online regexp validator and said me the regex has errors.

我该如何构建满足这些列出要求的正确正则表达式?

How do I construct a correct regexp that satisfy those listed requirements?

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-

推荐答案

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

You can give a try to this regex ^[^@]+[ ]*.*[ ]*([^;{}:]+)[ ]*$

它将涵盖除以下情况外的所有情况

It will cover you all cases except below one

不必匹配新行////

这篇关于在非空行中匹配换行符,并且不以某些字符开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆