GNU regcomp(3), regexec(3): '\w'
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Fri Jan 2 21:24:10 UTC 2004
On Fri, Jan 02, 2004 at 08:03:17PM +0200, Peter L. Peres wrote:
>
> Can you post an example (short) so we can compile and test whether it
> works here ?
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <string.h>
main ()
{
regex_t preg;
regmatch_t pmatch[1];
int a, b;
char *test;
if (regcomp (&preg, "\\w+", REG_EXTENDED) != 0) {
puts ("error in regcomp()");
exit (1);
}
test = "abc_123";
if (regexec (&preg, test, 1, pmatch, 0) != 0) {
puts ("error in regexec()");
exit (2);
}
a = pmatch[0].rm_so;
b = pmatch[0].rm_eo;
printf ("-- test={%s}, match={%s}\n", test, strndup (test + a, b - a));
regfree (&preg);
}
$ cc test.c -o test
$ ./test
-- test={abc_123}, match={abc_}
What I expected is
-- test={abc_123}, match={abc_123}
--
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Linux solution for data management and processing.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list