reg.cpp
资源名称:src.rar [点击查看]
上传用户:cqgdffbw
上传日期:2021-04-27
资源大小:17k
文件大小:1k
源码类别:
驱动编程
开发平台:
Unix_Linux
- #include <sys/types.h>
- #include <regex.h>
- #include <iostream>
- using namespace std;
- int main(int argc, char* argv[])
- {
- const char* regex = "[abc].*dog$";
- regex_t preg;
- int ret_val = regcomp(&preg, regex, REG_EXTENDED);
- if (ret_val != 0) {
- cout << "An error happen in regcomp " << endl;
- return 1;
- }
- ret_val = regexec(&preg, argv[1], 0, 0, 0);
- if (ret_val == REG_NOMATCH ) {
- cout << argv[1] << " does not match with the pattern! " << endl;
- }
- if (ret_val < 0)
- cout << "An error happens in regexec " << endl;
- if (ret_val == 0)
- cout << argv[1] << " match with the pattern! " << endl;
- regfree(&preg);
- return 0;
- }