Regular expression to recognize variable declarations in C

后端 未结 5 1392
我寻月下人不归
我寻月下人不归 2021-01-03 11:50

I\'m working on a regular expression to recognize variable declarations in C and I have got this.

[a-zA-Z_][a-zA-Z0-9]*

Is there any bette

5条回答
  •  清歌不尽
    2021-01-03 12:31

    This will eliminate return and typedef false flags. It is capable of capturing the return type and variable name, and supports pointers and arrays. It also eliminates commented code further reducing false flags in addition to detecting typedef variables.

    ^\s*(?!return |typedef )((\w+\s*\*?\s+)+)+(\w+)(\[\w*\])?(\s*=|;)
    

提交回复
热议问题