Reputation: 927
I used the code below that uses the "{}" but seems its not working as expected when using C.
int basic_regx(char *format, char *name)
{
regex_t regex;
char array[100];
if( regcomp(®ex, format, 0) )
return;
if( !regexec(®ex, name, 0, NULL, 0) )
printf ("Succeeded\n");
else
printf ("Not Succeeded\n");
regfree(®ex);
}
If I call function with follwoing:
Success - basic_regx("^[0-9]$","0");
Not Success -- basic_regx("^[0-9]{1,4}$","0");
Success - basic_regx("^[0-9]{1,4}$","0{1,4}");
Thats mean the {} is not taken as expected by the reg implementation.
Upvotes: 1
Views: 56
Reputation: 3213
regcomp
and regexec
use POSIX regular expressions; in other words, it only supports features described in POSIX. If you want Perl-style regular expressions, which support this expression, you may need an external library such as PCRE.
However, with POSIX regular expressions, you can do the equivalent:
basic_regx("^[0-9]\\{1,4\\}$","0");
Upvotes: 2