小亮写的 我分析不出来了 只好一个一个试了 :-(
#include<iostream>
int pos_after_star(const char *str, int &point_num, char &wildcard_flash)
{
if(!str)
{
return 0;
}
const char *_p = str;
char c = *_p;
int pos = 0;
point_num = 0;
while(*_p)
{
if(c == '*')
{
pos = _p + 1 - str;
wildcard_flash = '1';
}
else if ( c == '.' )
{
point_num++;
}
_p += 1;
c = *_p;
}
return pos;
}
int main()
{
//const char* str = "*.baidu.com"; // 1 2 1
const char* str = "www.*.baidu.com"; // 5 3 1
//const char* str = "*.baidu.com.cn"; // 1 3 1
//const char* str = "www.baidu.com.cn"; // 0 3
int pt = 0;
char flag;
int ret = pos_after_star(str, pt, flag);
std::cout<<"ret="<<ret<<std::endl; //*出现的位置 (从1开始数)
std::cout<<"pt="<<pt<<std::endl; //点的个数
std::cout<<"flag="<<flag<<std::endl; //有星就有正则
return 0;
}