Match newlines in non empty lines and not preceded by some characters

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 17:08:19

问题


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:


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



来源:https://stackoverflow.com/questions/35315675/match-newlines-in-non-empty-lines-and-not-preceded-by-some-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!