Is there a library which provides either compiled regular expressions or strings of regular expressions for common patterns such as IP addresses, hostnames, phone numbers, etc that is available in C, C++, C#, or Objective-C?
Ideally one that would allow code similar to the following:
#include <patterns.h>
#include <regex.h>
// return 1 if invalid IP or return 0 if valid IP address
int check_ip(const char * str)
{
regex_t re;
if ((regcomp(&re, pattern_ip_address(), REG_EXTENDED))
return(1);
if ((regexec(&re, str, 0, NULL, 0)))
{
regfree(&re);
return(1);
};
regfree(&re);
return(0);
}
Alternatively a header which defines a list of patterns such as PATTERN_IP_ADDRESS.