Parsing Java code with Java

前端 未结 5 1305
予麋鹿
予麋鹿 2021-01-29 11:32

Is it possible to parse some Java code with a regex?

So let\'s say I want a list of the int variables from this:



        
5条回答
  •  死守一世寂寞
    2021-01-29 12:07

    People often try to parse HTML, XML, C or java with regular expressions.

    With enough efforts and tricks, lot of amazing things are possible with complex combinations of regex. But you always end up with something very incomplete and not efficient.

    Regex can't handle complex grammars, use a parser, either generic or specific to java.

提交回复
热议问题