GNU bug report logs - #5970
regex won't do lazy matching

Previous Next

Package: coreutils;

Reported by: a g <mewalig <at> gmail.com>

Date: Mon, 19 Apr 2010 02:02:01 UTC

Severity: normal

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: a g <mewalig <at> gmail.com>
Subject: bug#5970: closed (Re: bug#5970: regex won't do lazy matching)
Date: Tue, 27 Apr 2010 22:31:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#5970: regex won't do lazy matching

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 5970 <at> debbugs.gnu.org.

-- 
5970: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5970
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Bob Proulx <bob <at> proulx.com>
To: a g <mewalig <at> gmail.com>
Cc: 5970-done <at> debbugs.gnu.org
Subject: Re: bug#5970: regex won't do lazy matching
Date: Tue, 27 Apr 2010 16:30:26 -0600
a g wrote:
> thanks for everyone's help. I agree this can be closed, but not for the
> reasons mentioned (though I appreciate them and they gave me the info I
> needed to find the answer:
> osdir.com/ml/lib.gnulib.bugs/2005-04/msg00027.html). Off to try emacs'
> regex.c instead.

Okay.  I will close the bug.

> It would be nice if coreutils could offer the emacs regex.c (or some other
> regex that supported non-greedy matching) at least as an additional library
> if not the standard one... but, not my call...

Though you did not answer my question as to your use of the regex
engine in coreutils I assume by this that you are trying to use it as
some type of general purpose library.  That really isn't its intended
purpose.  In coreutils it is there to support the regular expression
matching done in 'expr'.  For a general purpose library items it would
be better if you were to use gnulib or pcre or one of the other
libraries that is intended to be used as a library.

Bob

[Message part 3 (message/rfc822, inline)]
From: a g <mewalig <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: regex won't do lazy matching
Date: Sun, 18 Apr 2010 21:33:30 -0400
[Message part 4 (text/plain, inline)]
This may be a usage problem, but it does not exist with other regex packages
(such as slre) and I can't find anything in the documentation to indicate
that the syntax should be different for coreutils. I am using coreutils 8.4
on ubuntu AMD64, version 9.10. I cannot get the coreutils regex matcher to
do lazy matching. Here is my code:

/**** regex_test.cpp ***/
#include <stdio.h>
#include <stdlib.h>
#include "xalloc.h"
#include "regex.h"

// compile:
// gcc -I coreutils-8.4/lib/ -c regex_test.cpp
// g++ -o regex_test regex_test.o coreutils-8.4/lib/xmalloc.o
coreutils-8.4/lib/xalloc-die.o coreutils-8.4/lib/exitfail.o
coreutils-8.4/lib/regex.o

void print_regerror (int errcode, regex_t *compiled)
{
  size_t length = regerror (errcode, compiled, NULL, 0);
  char *buffer = (char *)xmalloc (length);
  if(!buffer) printf("error: regerror malloc failed!\n");
  else {
    (void) regerror (errcode, compiled, buffer, length);
    printf("error: %s\n", buffer);
    free(buffer);
  }
}

int main(int argc, char *argv[]){
  if(argc < 3) printf("usage: regex_test pattern string\n");
  else {
    regex_t rx;
    int err;
    if((err = regcomp(&rx, argv[1], REG_EXTENDED)))
      print_regerror(err, &rx);
    else {
      regmatch_t matches[4];
      if(!regexec(&rx, argv[2], 4, matches, 0)) {
int i;
 printf("match! \n");
for(i = 0; i < 4; i++) {
          if(matches[i].rm_so != -1)
            printf("  s:%i, e:%i", matches[i].rm_so, matches[i].rm_eo);
}
printf("\n");
      } else printf("match failed.\n");
      regfree(&rx);
    }
  }
}
/********/

Here is the problem. If you execute:
  regex_test "a[^x]*?a" "a1a2a"

then you get:
  match!
    s:0, e:5

But, you should get the same result as when you execute *regex_test
"a[^x]*?a" "a1a"*-- that is:
  match!
    s:0, e:3

Please advise. Thank you!
[Message part 5 (text/html, inline)]

This bug report was last modified 15 years and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.