Match newlines in non empty lines and not preceded

2019-09-20 08:32发布

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

  • Match newlines without matching preceding characters
  • Don't match newlines in only-space lines (empty lines)
  • Don't match newlines in lines started by optional spaces (not newlines) and at-symbol '@'.
  • Don't match newlines in lines containing [unescaped] '//'.
  • Don't match newlines preceded by '{', '}', ';' or ':'. (better if doesn't match newlines preceded by optional spaces and that characters.)

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-

1条回答
孤傲高冷的网名
2楼-- · 2019-09-20 09:25

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

It will cover you all cases except below one

doesn't have to match the new line //because of this

查看更多
登录 后发表回答