Hi,
I have a very simple question. How do i match a regex of :
a) (please disregard this question )
one or more digits
Example:
Code:
char text[] = "x34c"
char reg[]="x([0-9]{2})c";
regex(reg,text);
this will match my two digits after x but how to make it match all the digits between x and c given that ia don't know how many digit there are
b)
real number
my regex function is as follows:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <regex.h>
#include <stdlib.h>
#define NUM_MATCHES 4
int regex (char *reg, char *text, int *regout){
regex_t myreg;
regmatch_t mymatch[NUM_MATCHES];
int rm, i,r=0;
char myom[1024];
rm = regcomp (&myreg, reg, REG_EXTENDED) ;
rm =regexec (&myreg, text, NUM_MATCHES, mymatch, 0);
for (i = 1; !rm && i <= myreg.re_nsub; i++){
r++;
strncpy (myom, text + mymatch[i].rm_so, mymatch[i].rm_eo - mymatch[i].rm_so);
myom[mymatch[i].rm_eo - mymatch[i].rm_so] = '\0';
regout[i-1] = atoi(myom);
}
regfree (&myreg);
return r -1;
}
int main (){
int regout[2], i;
int r;
char text[] = "x34c"
char reg[]="x([0-9]{2})c";
r = regex(reg,argv[1],regout);
printf("r:%d\n",r);
for(i=0;i<r;i++){
printf("digit:%d\n", regout[i]);
}
P.S.
also would this be the right (fastest) way to load a file of this type into memory:
file example:
Code:
#type:12
#tex:HHt6TT
$$jksdfhusd7swdf76t6dfs77::CH1
51 [tab] 75
23 [tab] 7548
57 [tab] 78
56 [tab] 7
3 [tab] 711
1 [tab] 71
#type:1
#tex:HGtz7
$$soookldio343s77::CH1
46 [tab] 78
26 [tab] 67
57 [tab] 45
59 [tab] 23
23 [tab] 72
89 [tab] 74
[tab] is a tab separator. I need to upload into my memory table only the type number (1 from #type:1) and the two column table (numbers). I was thinking of regex but would that be the best way to go ??