이제 "href ="http://www.AAA.com ""및 다른 문자와 같은 많은 하위 문자열이 있습니다 여기 내 질문에, 내 C에서 코드 작성 :C와 함께 pcre에 적절한 패턴을 작성하는 방법
char pattern [] = "/^href.*>$/g";
및 긴 문자열의 모든 URL을 선택하고 싶습니다. 하지만 그건 효과가 없어. 어떤 사람들이 나를 도와 줘? 귀하의 도움을 주시면 감사하겠습니다. 다음은 코드입니다 :
#define PCRE_STATIC //
#include <stdio.h>
#include <string.h>
#include <pcre.h>
#define OVECCOUNT 30 /* should be a multiple of 3 */
#define EBUFLEN 128
#define BUFLEN 1024
int main()
{
pcre *re;
const char *error;
int erroffset;
int ovector[OVECCOUNT];
int rc, i;
char src[] = "<a href=\"http://union.elong.com/r/hotel/2000000000855850825\" target=\"_blank\">ss</a></td></tr><tr><td><a href=\"http://123.sogou.com/sub/fanyi.html\" targedd</a></td><td><a href=\"http://123.sogou.com/sub/fantizi.html\" target=\"_blank\">繁 体 字</a></td><td><a href=\"http://123.sogou.com/sub/kuaidi.htm>快递查询</a></td></tr><tr><td><a href=\"http://q.stock.sohu.com/index.shtm>股票行情</a></td><td><a href=\"http://www.chinamobile.com/service/billservice/>话费查询</a></td><td><a href=\"http://auto.sohu.com/s2004/weizhangchaxun.shtml>交通违章</a></td></tr><tr><td>";
char pattern[] = "/^href.*>$/g";
re = pcre_compile(pattern,
0,
&error,
&erroffset,
NULL);
if (re == NULL) {
printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
return 1;
}
rc = pcre_exec(re,
NULL,
src,
strlen(src),
0,
PCRE_MULTILINE,
ovector,
OVECCOUNT);
if (rc < 0) {
if (rc == PCRE_ERROR_NOMATCH) printf("Sorry, no match ...\n");
else printf("Matching error %d\n", rc);
pcre_free(re);
return 1;
}
printf("\nOK, %d has matched ...\n\n",rc);
for (i = 0; i < rc; i++) {
char *substring_start = src + ovector[2*i];
int substring_length = ovector[2*i+1] - ovector[2*i];
printf("$%2d: %.*s\n", i, substring_length, substring_start);
}
pcre_free(re);
return 0;
}
개 코드를 입력하고, 원하는 출력을 입력 해주십시오. – FailedDev
나는 char pattern [] = "href. *>"을 시도했다. 나 한테만 결과를 줄 수있어. 나는 모든 URL을 찾아야 해. – Hession