First of all I would like to thank you for your quick response. I modified the code in the following way:
Code:
regex_t r;
char *str = "777777777.77777e333 333.333 string one string two";
regmatch_t matches[3];
regcomp(&r, "([0-9]{7,9}\\.[0-9]{5}e[0-9]{2,3}) ([0-9]{3}\\.[0-9]{3})", REG_EXTENDED);
regexec(&r, str, 3, matches, 0);
printf ("Found at %d %d \n",matches[0].rm_so,matches[0].rm_eo);
printf ("Found at %d %d \n",matches[1].rm_so,matches[1].rm_eo);
printf ("Found at %d %d \n",matches[2].rm_so,matches[2].rm_eo);
Which gives the desired result, the offsets of the string which I am looking for :
Code:
Found at 0 27
Found at 0 19
Found at 20 27
I guess that in matches[0].rm_so,matches[0].rm_eo the offsets of the whole
Code:
([0-9]{7,9}\\.[0-9]{5}e[0-9]{2,3}) ([0-9]{3}\\.[0-9]{3})
I just need to figure out how to print the string, if I use
Code:
mat=strndup(str+matches[1].rm_so,matches[1].rm_eo);
printf(mat);
I get Segmentation fault.
Or some way in order to initialize the results from matching to variables. I would be grateful if you can help me with this. I would be also very grateful if you can recommend some book or online resource where I can read more about using regular expressions with regex.h .