加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式解析C枚举

发布时间:2020-12-14 05:46:51 所属栏目:百科 来源:网络整理
导读:如何构造正则表达式来解析C枚举? 我试过的枚举看起来像 enum Temperature{ C = 0,F=1,// some elements are commented R,// most elements are not gived a value K // sometimes the last element is succeeded by a comma} temperature;// different inde
如何构造正则表达式来解析C枚举?
我试过的枚举看起来像

enum Temperature
{
    C = 0,F=1,// some elements are commented
    R,// most elements are not gived a value
    K        // sometimes the last element is succeeded by a comma
} temperature;

// different indent style is used
enum Depth {
    m = 0,ft = 1,} depth;

我尝试了几个简单的模式,但没有一个足以捕捉上述所有情况.

任何可以帮助我的regexp向导?

编辑:澄清,我想要名称和价值,例如C和0.

解决方法

这很有挑战性:)下面是我能想到的最好的.假设只给出{和}之间的文本,它会捕获所有名称和相应的值:

/(w+)s*(?:=s*(d+)|)s*,?s*(?:(?:n|$)|//.*?(?:n|$)|)/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读