{
const char *regex = "href=\"[^ >]*\"";
regex_t preg;
const size_t nmatch = 10;
regmatch_t pm[nmatch];
if (regcomp(&preg, regex, 0) != 0) { /*编译正则表达式失败 */
perror("regcomp");
exit(1);
}
int z, i;
z = regexec(&preg, buf, nmatch, pm, 0);
if (z == REG_NOMATCH)/*无匹配项 */
{
return 0;
}
else/*有匹配的超链接 */
{
for (i = 0; i < nmatch && pm[i].rm_so != -1; ++i)/*把超链接都提取出*/
{
/*对匹配链接的操作*/
}
}
regfree(&preg);/*释放正则表达式*/
}
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
#include <string.h>
static char* substr(const char*str, unsigned start, unsigned end)
{
}
int main(int argc, char** argv)
{
{
{
{
{
}
编译执行
bitwangbin@mac:~/code/c/regex > gcc regexp.c -o regexp
bitwangbin@mac:~/code/c/regex > ./regexp
0003: #include <regex.h>;
0020:
0037: