Regexp in C - match group

后端 未结 3 951
[愿得一人]
[愿得一人] 2021-01-15 04:25

I\'ve been struggling with regular expressions in C (just /usr/include/regex.h).


I have (let\'s say) hundreds of regexps and one of them can match

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 04:46

    You could have them give you a array of strings that contain your regexps and test each one of them.

    //count is the number of regexps provided
    int give_me_number_of_regex_group(const char *needle,const char** regexps, int count ){
      for(int i = 0; i < count; ++i){
        if(regex_match(needle, regexp[i])){
          return i;
        }
      }
      return -1; //didn't match any
    }
    

    or am i overseeing something?

提交回复
热议问题