|
发表于 2021-2-2 15:04:49
|
显示全部楼层
不知道是不是你想要的效果
- #include<iostream>
- #include <regex>
- using namespace std;
- int main()
- {
- char g[100] = { "as65d4sa6d556sad6d16s5a165sf4fsdaf544" };
- int a[100] = { 0 };
- int i = 0;
- int tmp1 = 0, tmp2 = 0;
- char *p = g;
- while (*p != '\0')
- {
- if (*p >= 48 && *p <= 57 && 0 == i)
- {
- i++;
- tmp1 = *p;
- }
- else if (*p >= 48 && *p <= 57 && 1 == i)
- {
- tmp2 = *p;
- printf("%c%c\n", tmp1, tmp2);//tmp1 tmp2 组合成一个数存进数组自己写吧
- i = 0;
- tmp1 = 0;
- tmp2 = 0;
- }
- else if(1 == i)
- {
- i = 0;
- tmp1 = 0;
- tmp2 = 0;
- }
- p++;
- }
- cout << "----正则实现----" << endl;
- string str = g;
- regex reg("\\d{2}");
- sregex_iterator it(str.cbegin(), str.cend(), reg);
- sregex_iterator end;
- for (; it != end; ++it)
- {
- cout << it->str() << endl;
- }
- return 0;
- }
复制代码
|
|