why \w pattern can’t match?and many pattern can’t work,eg:\s
my os is Mac
I think maybe missing something;
that code only match char ‘w’,don’t sam.
thank your help
//
// main.c
// test
//
// Created by SamPeng on 12-9-22.
// Copyright (c) 2012年 SamPeng. All rights reserved.
//
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
#include <string.h>
int main(int argc, const char * argv[])
{
int status,i;
int cflags = REG_EXTENDED;
regmatch_t pmatch[1];
const size_t nmatch=1;
regex_t reg;
const char *pattern="\\w";
char *buf = "sam@sampengw.org";
regcomp(®, pattern, cflags);
status = regexec(®, buf, nmatch, pmatch, 0);
if(status == REG_NOMATCH)
printf("No Match \n");
else if(status == 0){
printf("Match:\n");
for (i=pmatch[0].rm_so; i<pmatch[0].rm_eo; ++i) {
putchar(buf[i]);
}
printf("\n");
}
regfree(®);
return 0;
}
complement:
yes,I know this work is POSIX Base reg,how change this? I wan’t use powerful regex
The glib regex module supports POSIX extended regular expressions, which allow only a small subset of modern regular expression syntax, due to having been standardized in 1986. For shorthand classes like
\wand\s, you want either the GNU extensions (available in Gnulib) or the PCRE library.