/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* This is an example of the function regexec(const regex_t *,const char, size_t   regmatch_t [], int).  This function will attempt to match the expression 
   held in "string" with the compiled expression stored in "reg".  If a match
   occurs, then zero will be returned, else, a non negative number will be 
   returned.
*/
#include <regex.h>
#include <stdio.h>
#include <sys/types.h>

int main() {
    regex_t reg;        
    int  cflags, retval, eflags;
    char  *string, *pattern,errbuf[100];
    size_t nmatch, errbuf_size;
    string = "abcd";
    pattern = "x";
    eflags = REG_NEWLINE; 
    cflags = REG_NEWLINE;
    errbuf_size = 100;

    retval = regcomp(&reg, pattern,cflags);
    if (retval != 0) {
    	(void)regerror(retval,&reg,errbuf,errbuf_size);
     	printf("%s\n",errbuf);
    	return(0);                       /* report error */
    } 
    retval = regexec(&reg, string,(size_t) 0,NULL,eflags);
    if (retval != 0) {
        (void)regerror(retval,&reg,errbuf,errbuf_size);
        printf("%s\n",errbuf);
        return(0);                       /* report error */
    }
    else
	printf("Success\n");
}

