A
apoorva.groups
Hi
I am facing problem while using regexec function.
Ex: String = "abc_def_hig"
sub string = "def"
regexc if I use regexec the it will find the sub string in string and
it will return 0.
I want to modify the sub string such that it matches only if the
string "starts" with the sub string.
if String = "def_abc_hig and sub_String = "def"
then only regexec should return 0
else String is "abcdefhig" and sub_String = "def"
the regexec should fail
I tried using ^ in from of the sub string but then it does not event
match the String.
here is the code snippet.
*****************************************************************************
int regexpress ( char *string, char *pattern )
{
regex_t * regex;
printf("\nInside regex\n");
regex = ( regex_t *) malloc (sizeof(regex_t));
if(regcomp(regex, pattern, REG_EXTENDED)!=0) {
printf("\nERROR\n");
return -1;
}
if (regexec(regex, string, 0, NULL, 0)==0) {
printf("\nInside regexpress pattern found\n");
regfree(regex);
free(regex);
return 1;
}
else {
printf("\nInside else\n");
regfree(regex);
free(regex);
return -22;
}
}
retCode = regexpress( "abcdefhig", "def");
if (retCode == 1){
printf("\npattern found file found\n");
return 1;
}
retCode = regexpress( "defabchig", "def");
if (retCode == 1){
printf("\npattern found file found\n");
return 1;
}
*************************************************************************************
I want that the Ist regexpress function to return 0 and 2nd regexpress
function to return 1
What Pattern should i be sending
Thanks In Advance
I am facing problem while using regexec function.
Ex: String = "abc_def_hig"
sub string = "def"
regexc if I use regexec the it will find the sub string in string and
it will return 0.
I want to modify the sub string such that it matches only if the
string "starts" with the sub string.
if String = "def_abc_hig and sub_String = "def"
then only regexec should return 0
else String is "abcdefhig" and sub_String = "def"
the regexec should fail
I tried using ^ in from of the sub string but then it does not event
match the String.
here is the code snippet.
*****************************************************************************
int regexpress ( char *string, char *pattern )
{
regex_t * regex;
printf("\nInside regex\n");
regex = ( regex_t *) malloc (sizeof(regex_t));
if(regcomp(regex, pattern, REG_EXTENDED)!=0) {
printf("\nERROR\n");
return -1;
}
if (regexec(regex, string, 0, NULL, 0)==0) {
printf("\nInside regexpress pattern found\n");
regfree(regex);
free(regex);
return 1;
}
else {
printf("\nInside else\n");
regfree(regex);
free(regex);
return -22;
}
}
retCode = regexpress( "abcdefhig", "def");
if (retCode == 1){
printf("\npattern found file found\n");
return 1;
}
retCode = regexpress( "defabchig", "def");
if (retCode == 1){
printf("\npattern found file found\n");
return 1;
}
*************************************************************************************
I want that the Ist regexpress function to return 0 and 2nd regexpress
function to return 1
What Pattern should i be sending
Thanks In Advance