Since "HELLO" is really an exact match (unlike "H.?LLO"), you might as well just iterate through your line one character at a time. But I presume your wanted substring is actually something else, or you wouldn't be asking this question -- unless you just want to check if HELLO is present.
This is more or less what I've been using:
Code:
#include <regex.h>
struct matchspec {
int bgn;
int end;
} rgxp;
char *regexp (char *string, char *patrn) {
short int i, w=0, len;
char *word = NULL;
regex_t rgT;
regmatch_t match;
regcomp(&rgT,patrn,REG_EXTENDED);
if ((regexec(&rgT,string,1,&match,0)) == 0) {
rgxp.bgn = (int)match.rm_so;
rgxp.end = (int)match.rm_eo;
len = rgxp.end-rgxp.bgn;
word=malloc(len+1);
for (i=rgxp.bgn; i<rgxp.end; i++) {
word[w] = string[i];
w++; }
word[w]=0; //make sure this string is terminated
}
regfree(&rgT);
return word;
}
regexp(yourline,"H.*O") (for example) will put the character positions of the match into global struct rgxp as rgxp.bgn and rgxp.end. The first character in a line is zero and I believe the "end" value is actually the character after the "O". If there is no match, you get a NULL pointer. If there is a match, you get the content of the match returned (ie. "HEL+O" could return "HELLO").
Good luck. nb. this only returns the first match, but qv. the method in my next post for the next match