如何在C語言中使用正則表示式
阿新 • • 發佈:2019-01-28
查閱了百度,借鑑了許多大牛的程式碼,自己的整理如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
//例1:從<sip:[email protected]>中提取tom
const char* url = "<sip:[email protected]>";
char uri[10] = {0};
sscanf(url, "%*[^:]:%[^@]", uri);
cout << uri << endl;
//例2:從iios/ [email protected]中提取 12DDWDFF
const char* s = "iios/[email protected]";
char buf[20];
sscanf(s, "%*[^/]/%[^@]", buf);
cout << buf << endl;
int k;
sscanf( "AAA123BBB456" , "%*[^0-9]%i" , &k) ;
printf("%d\n",k);
return 0;
}