NO

Author Topic: I cannot use regular expressions  (Read 7183 times)

Offline bitcoin

  • Member
  • *
  • Posts: 179
I cannot use regular expressions
« on: October 10, 2018, 04:54:35 AM »
I want to use regular expressions in pure C (not C++), but i cannot use it! I search the source in internet:
Code: [Select]
#include <stdio.h>
#include <regex.h>

int main(int argc,char *argv[])
{
regex_t regex;
int reti;
char msgbuf[100];

/* Compile regular expression */
reti = regcomp(&regex, "^a[[:alnum:]]", 0);
if (reti) {
    fprintf(stderr, "Could not compile regex\n");
    return 1;
}

/* Execute regular expression */
reti = regexec(&regex, "abc", 0, NULL, 0);
if (!reti) {
    puts("Match");
}
else if (reti == REG_NOMATCH) {
    puts("No match");
}
else {
    regerror(reti, &regex, msgbuf, sizeof(msgbuf));
    fprintf(stderr, "Regex match failed: %s\n", msgbuf);
     return 1;
}

/* Free memory allocated to the pattern buffer by regcomp() */
regfree(&regex);

return 0;
}
But i have errors:
Code: [Select]
..path..b.c(9): error #2048: Undeclared identifier 'regex_t' (did you mean: ?).
..path..b.c(9): error #2001: Syntax error: expected ';' but found 'regex'.
..path..b.c(9): error #2048: Undeclared identifier 'regex' (did you mean: ?).
..path..b.c(14): warning #2018: Undeclared function 'regcomp' (did you mean: rename?); assuming 'extern' returning 'int'.
..path..b.c(21): warning #2018: Undeclared function 'regexec' (did you mean: rename?); assuming 'extern' returning 'int'.
..path..b.c(25): error #2048: Undeclared identifier 'REG_NOMATCH' (did you mean: ?).
..path..b.c(29): warning #2018: Undeclared function 'regerror' (did you mean: ?); assuming 'extern' returning 'int'.
..path..b.c(35): warning #2018: Undeclared function 'regfree' (did you mean: rename?); assuming 'extern' returning 'int'.
*** Error code: 1 ***

Why this happens? Or say me, where i can get PCRE header and lib file, maybe it will be easier with this lib.


Sorry for bad English, i am not eng.speaking

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: I cannot use regular expressions
« Reply #1 on: October 10, 2018, 10:07:59 AM »
Use compiler option -Go Define compatibility names.
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: I cannot use regular expressions
« Reply #2 on: October 10, 2018, 10:43:58 AM »
Thank you, mr. Cat! All works!)