Tested on regexpal.com this regex works fine, but when run in my program it doesn’t work at all. The objective is to pull the video ID from the url (And throw an error if it’s not a valid url)
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
regex_t expression;
char * regexpression = "^(https?://)?(www\\.)?youtube\\.com/watch\\?(.*&)?v=(.*?)(&.*)?$";
regcomp(&expression,regexpression,0);
char * url = "http://www.youtube.com/watch?v=HereBeVideoId";
if(regexec(&expression, url, 0, NULL, 0)){
printf("Url %s not a valid video.\n",url);
return;
}
return 0;
}
Add
REG_EXTENDEDflag toregcomp()function: