정규식 표현 관련.
글쓴이: papa3721 / 작성시간: 일, 2007/10/21 - 8:10오후
p="^\s*.\s*";
패턴에 관련 부분에. 문자열에 점이 있는지 없는지만 검사하려고 하는데.
어떻게 해야 하나요?
#include <regex.h>
#include <stdio.h>
/*
* Match string against the extended regular expression in
* pattern, treating errors as no match.
*
* return 1 for match, 0 for no match
*/
int match(const char *string, char *pattern)
{
int s;
regex_t re;
if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
return(0); /* report error */
}
s = regexec(&re, string, (size_t) 0, NULL, 0);
regfree(&re);
if (s != 0) {
return(0); /* report error */
}
return(1);
}
int main()
{
char * p="^\s*.\s*";
char * s="asdfas.uu";
if(match(s,p) == 0)
printf("no match\n");
else
printf("yes match\n");
return 0;
}Forums:


원하는 결과에 따라서 다르겠지만...
일단은
"^.*..*$"
와 같이 쓰시면 되겠네요.
Good Bye, Cruel World!
댓글 달기