Can someone compile and run this on Linux?

The code below fails to match the string "a" to the regex "^a$" on MacOSX if both "REG_EXTENDED | REG_ENHANCED" are specified, but it will pass if just REG_ENHANCED is used.

Can someone run this on linux to see if the code below fails as well on linux? I want to make sure it isn't just an old version of regex we have in our libc...

#include <stdio.h>
#include <stdint.h>
#include <regex.h>

#define DEFAULT_REG_FLAGS (REG_EXTENDED | REG_ENHANCED)

int main (int argc, char const *argv[], char const *envp[])
{
    regex_t re;
    const char *regex_input = "a";
    int err = regcomp (&re, "^a$", DEFAULT_REG_FLAGS);
    if (err == 0)
    {
        err = regexec (&re, regex_input, 0, NULL, DEFAULT_REG_FLAGS);
        if (err == 0)
        {
            puts("matched");
        }
        else
        {
            char error_str[2048];
            const size_t actual_error_str_size = regerror(err, &re, error_str, sizeof(error_str));
            puts(error_str);
        }
    }
    return 0;
}

Hi Greg,

The code below fails to match the string "a" to the regex "^a$" on MacOSX if both "REG_EXTENDED | REG_ENHANCED" are specified, but it will pass if just REG_ENHANCED is used.

REG_ENHANCED doesn't appear to exist in regex.h derived from
glibc-2.19. Is it a new flag?

Cheers.

Tim

Linus doesn’t appear to have REG_ENHANCED.

vharron@tifa:~$ gcc foo.cpp
foo.cpp: In function ‘int main(int, const char**, const char**)’:
foo.cpp:5:43: error: ‘REG_ENHANCED’ was not declared in this scope
#define DEFAULT_REG_FLAGS (REG_EXTENDED | REG_ENHANCED)
^
foo.cpp:11:36: note: in expansion of macro ‘DEFAULT_REG_FLAGS’
int err = regcomp (&re, “^a$”, DEFAULT_REG_FLAGS);

vharron@tifa:~$ clang foo.cpp
foo.cpp:11:36: error: use of undeclared identifier ‘REG_ENHANCED’
int err = regcomp (&re, “^a$”, DEFAULT_REG_FLAGS);
^
foo.cpp:5:43: note: expanded from macro ‘DEFAULT_REG_FLAGS’
#define DEFAULT_REG_FLAGS (REG_EXTENDED | REG_ENHANCED)
^
foo.cpp:14:51: error: use of undeclared identifier ‘REG_ENHANCED’
err = regexec (&re, regex_input, 0, NULL, DEFAULT_REG_FLAGS);
^
foo.cpp:5:43: note: expanded from macro ‘DEFAULT_REG_FLAGS’
#define DEFAULT_REG_FLAGS (REG_EXTENDED | REG_ENHANCED)
^
2 errors generated.

s/Linus/Linux/

If I remove REG_ENHANCED and compile/run I get “No match” =(

By the way, are you asking this because of some LLDB code? If so, I would rather standardize on std::regex. Consistent rules across all platforms, and supported everywhere AFAIK.

http://www.manpagez.com/man/3/regcomp/