在C ++代码中查找类声明的正则表达式 [英] Regular expressions to find class declarations in C++ code

查看:123
本文介绍了在C ++代码中查找类声明的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来寻找类声明,所以我可以在class关键字之前添加一个#define。

解决方案

正则表达式不必是完美的,只要它能捕获大多数情况。  /.* class\s +([^ {] +)\s * [:]?([^ {] +){/ 
pre>

这应该适用于大多数类定义,包括模板类。类名称捕获在$ 1中,如果它是派生类,则基数将为$ 2。


I need a regular expression for finding class declarations so I can add a #define before the "class" keyword. The regular expression doesn't have to be perfect, just good enough that it catches most of the cases.

解决方案

/.*class\s+([^{]+)\s*[:]?([^{]+){/

This should work for most class definitions, including template classes. The class name is captured in $1 and if it is a derived class, the base will be in $2.

这篇关于在C ++代码中查找类声明的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆