NO

Author Topic: Regular expression won't compile.  (Read 1894 times)

gbr

  • Guest
Regular expression won't compile.
« on: May 26, 2020, 04:32:57 PM »
I'm trying to match the filename base and the extension of a Windows file path.

I'm using a using a regex that I've used before, from here :
https://web.archive.org/web/20190505200101/http://movingtofreedom.org/2008/04/01/regex-match-filename-base-and-extension/
the regex is (.+?)(\.[^.]*$|$)

Code: [Select]

char * source = "F:\\Pelles C Programs\\test\\test.exe";
char * regexString = "(.+\?)(\\.[^.]*$|$)";
regex_t regexCompiled;

  if (regcomp(&regexCompiled, regexString, REG_EXTENDED))
    {
      printf("Could not compile regular expression.\n");
      return 1;
    };


But regcomp returns a error.
if I print regexString, it is exactly as I mentioned above.



EDIT : Came across this :
Quote
The *? non-greedy operators is an enhanced non-POSIX feature borrowed from Perl. You get them with REG_ENHANCED.
Is that the reason ?

« Last Edit: May 26, 2020, 05:29:42 PM by gbr »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Regular expression won't compile.
« Reply #1 on: May 26, 2020, 06:34:20 PM »
As far as I know PellesC regex are based on original Henry Spencer code, that don't supports non-greedy operators (and many other new features).
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide