关于正则表达式(C++)

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:52:37
帮我写一个能提取<a href="http:// " 引号中超连接的表达式(只需要http打头的即可,谢谢

#include <stdio.h>
#include <assert.h>
#include <string.h>

//<a href="http:// "

int ExtractHttp(char* pHttp, const char* psz_)
{
assert(pHttp && psz_);

int nNumb = 0;
int nFrom = 0, nTo = 0;
const char* psz = psz_;
while( *psz )
{
if( '"' == *psz )
{
if( 0 == nNumb ) // the 1st "
{
nNumb++;
nFrom = psz - psz_;
}
else
{
nNumb++; // the 2nd
nTo = psz - psz_;
break;
}
}

psz++;
}

if( nNumb != 2 ) return 0;

int nCount = nTo - nFrom - 1;
memcpy(pHttp, psz_ + nFrom + 1, nCount);
pHttp[nCount] = '\0';

return nCount;
}

int main()
{
char sz1v[200];
char* psz = "<sdfsdasa, \"