Why is regex always true or always false

前端 未结 1 855
刺人心
刺人心 2021-01-24 14:00

I am trying to use a regex to determine if a provided file has the .csv extension.

#include 
#include 

int match(const char *strin         


        
1条回答
  •  無奈伤痛
    2021-01-24 14:20

    The regex you are using is not valid for the regex flavor: the hyphen must be used at the start/end of the bracket expression. Also, you need to escape the dot, else, it will match any char.

    Use

    const char *reg = "^[a-zA-Z0-9_-]+\\.csv$";
    

    See the C demo.

    0 讨论(0)
提交回复
热议问题