mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Different results with regex.h between Musl and Libc
@ 2024-06-10  5:38 Nigel Kukard
  2024-06-10 11:47 ` [musl] " Valery Ushakov
  0 siblings, 1 reply; 4+ messages in thread
From: Nigel Kukard @ 2024-06-10  5:38 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 2036 bytes --]

Hi there,

I'm wondering if someone could possibly point out what I'm doing wrong here.

I tried searching the mailing list for similar topics, I found some 
relating to POSIX regex but none that really dealt with this issue with 
extended regex. I also didn't find anything really addressing this on 
https://wiki.musl-libc.org/functional-differences-from-glibc.html.

If I missed something I'm terribly sorry.


Musl output (Alpine 3.20), musl-1.2.5-r1...

The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1:
Match 2: 37

Glibc output (ArchLinux), glibc 2.39+r52+gf8e4623421-1...

The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1: 37
Match 2:


Test code...
/*--------------------*/
#include <stdio.h>
#include <regex.h>

int main() {
     const char *pattern = "^([0-9]*)?\\.?([0-9]*)?$";
     const char *input = "37";
     regex_t regex;
     regmatch_t matches[3];
     int ret;

     ret = regcomp(&regex, pattern, REG_EXTENDED);
     if (ret) {
         fprintf(stderr, "Could not compile regex\n");
         return 1;
     }

     ret = regexec(&regex, input, 3, matches, 0);
     if (!ret) {
         printf("The input '%s' matches the pattern '%s'\n", input, 
pattern);
         for (int i = 0; i < 3; i++) {
             if (matches[i].rm_so != -1) {
                 printf("Match %d: %.*s\n", i, matches[i].rm_eo - 
matches[i].rm_so, input + matches[i].rm_so);
             }
         }
     } else if (ret == REG_NOMATCH) {
         printf("The input '%s' does not match the pattern '%s'\n", 
input, pattern);
     } else {
         char msgbuf[100];
         regerror(ret, &regex, msgbuf, sizeof(msgbuf));
         fprintf(stderr, "Regex match failed: %s\n", msgbuf);
         return 1;
     }

     regfree(&regex);

     return 0;
}


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-10 18:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-10  5:38 [musl] Different results with regex.h between Musl and Libc Nigel Kukard
2024-06-10 11:47 ` [musl] " Valery Ushakov
2024-06-10 15:56   ` Rich Felker
2024-06-10 17:57     ` Valery Ushakov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).