Regex that Will Match a Java Method Declaration

后端 未结 14 1282
半阙折子戏
半阙折子戏 2020-11-27 17:53

I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to

14条回答
  •  迷失自我
    2020-11-27 18:46

    As of git 2.19.0, the built-in regexp for Java now seems to work well, so supplying your own may not be necessary.

    "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
    "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$"
    

    (The first line seems to be for filtering out lines that resemble method declarations but aren't.)

提交回复
热议问题