I’m having a bit of difficulty setting up a regex to match a URL using the regex.h library in C. I have a working IP regex that I was hoping to convert to match a simple string such as www.alphanumerictext12.com|edu|org. Something is wrong with my syntax in the regex definition itself.
Below is the working IPREGEX code and my attempted URL regex.
#define IPEXPR "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})"
#define URLEXPR "(www)\\.((?:[a-z][a-z]*[0-9]+[a-z0-9]*))\\.(com|edu|org)"
regex_t regex;
if(regcomp(®ex, IPEXPR, REG_EXTENDED) != 0)
return 0;
if(regexec(®ex, inputURL, 0, NULL, 0) != 0)
return 0;
Try:
I removed the
[0-9]+and replaced[a-z][a-z]*with[a-z]+.