regex

G

gert

http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

errcode=regcomp(&re, "test", REG_EXTENDED);
if(errcode==0)errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
errcode=regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL);
}

Can anybody tel me why this get stuck in a loop and how to unstuck it
please ?
Second problem is that "x(?=x)" is a invalid expression ?

PS i know off topic but i had not much luck at comp.programming, the
source is in c doh :)
 
G

gert

http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

errcode=regcomp(&re, "test", REG_EXTENDED);
if(errcode==0)errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
errcode=regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL);

}

Can anybody tel me why this get stuck in a loop and how to unstuck it
please ?
Second problem is that "x(?=x)" is a invalid expression ?

PS i know off topic but i had not much luck at comp.programming, the
source is in c doh :)

aha my brother told me something about a offset :)

http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

now i only need figure out why there is this weird character at the
end of each line ?
 
M

Martin Ambuhl

gert said:
http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

errcode=regcomp(&re, "test", REG_EXTENDED);
if(errcode==0)errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
errcode=regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL);
}

Can anybody tel me why this get stuck in a loop and how to unstuck it
please ?

Apparently
regcomp(&re, "test", REG_EXTENDED) == 0 and
regexec(&re, &buffer[0], 1, &rm, 0) == 0 and then
always regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL) == 0
Since neither of the functions regcomp nor regexec,
and neither of the macros REG_EXTENDED nor REG_NOTBOL
have any defined many in C, it is impossible to guess how to be make
any of these return a non-zero value.

Fix it by creating conditions for one of the first two to be non-zero
before the loop or by making sure that the third one sometime will
return non-zero.
Second problem is that "x(?=x)" is a invalid expression ?

What, in the name of all that's holy, did you imagine it to mean? Since
when was "?" an identifier naming a modifiable object?
PS i know off topic but i had not much luck at comp.programming, the
source is in c doh :)

How would you know what was C?
 
M

Malcolm McLean

gert said:
http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

errcode=regcomp(&re, "test", REG_EXTENDED);
if(errcode==0)errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
errcode=regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL);
}

Can anybody tel me why this get stuck in a loop and how to unstuck it
please ?
Second problem is that "x(?=x)" is a invalid expression ?

PS i know off topic but i had not much luck at comp.programming, the
source is in c doh :)
The loop is topical enough. regexec must be returning zero.
You might need to escape special characters like parentheses. The way to
tackle such problems, if the documentation won't help, is to write a program
to match "Fred", then F?ed, and so on, buliding up until you can see where
the pattern is going wrong.
 
M

Malcolm McLean

Malcolm McLean said:
gert said:
http://dfo.svn.sourceforge.net/viewvc/dfo/trunk/cgi/csv.c?view=markup

errcode=regcomp(&re, "test", REG_EXTENDED);
if(errcode==0)errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
errcode=regexec(&re, buffer+rm.rm_eo, 1, &rm, REG_NOTBOL);
}

Can anybody tel me why this get stuck in a loop and how to unstuck it
please ?
Second problem is that "x(?=x)" is a invalid expression ?

PS i know off topic but i had not much luck at comp.programming, the
source is in c doh :)
The loop is topical enough. regexec must be returning zero.
Correction, or it is not returning at all. It is hard to believe that a
library function would be so poorly designed, but not impossible. Put in a
diagnostic printf() to work out which.
 
K

Keith Thompson

Martin Ambuhl said:
gert wrote: [snip]
Second problem is that "x(?=x)" is a invalid expression ?

What, in the name of all that's holy, did you imagine it to mean?
Since when was "?" an identifier naming a modifiable object?

I suspect that "x(?=x)" is meant to be part of a regular expression,
not a C expression. Whether it's valid, and if so what it means, is
likely to depend on which regular expression library the OP is using.

No, don't bother telling us; whichever one it is, it's off-topic here.
You'll need to read the library's documentation and/or ask in a forum
where it's topical (possibly comp.unix.programmer).

(If "x(?=x)" *was* meant to be a C expression (and not a string
literal), then I can only echo Martin's comment: What, in the name of
all that's holy, did you imagine it to mean?)
 
G

gert

I suspect that "x(?=x)" is meant to be part of a regular expression,
not a C expression. Whether it's valid, and if so what it means, is
likely to depend on which regular expression library the OP is using.

No, don't bother telling us; whichever one it is, it's off-topic here.
You'll need to read the library's documentation and/or ask in a forum
where it's topical (possibly comp.unix.programmer).

(If "x(?=x)" *was* meant to be a C expression (and not a string
literal), then I can only echo Martin's comment: What, in the name of
all that's holy, did you imagine it to mean?)

Well the C book from Jesus told me x(?=x) is not a POSIX regular
expression. Anyway i know now what i am looking for namely a other
regexp API.
 
A

Azazel

Well the C book from Jesus told me x(?=x) is not a POSIX regular
expression. Anyway i know now what i am looking for namely a other
regexp API.

In Perl it's a zero-width look-ahead assertion. It matches an x
followed by another x, without consuming the latter one. From the
perlre(1) man-page:

"(?=pattern)"
A zero-width positive look-ahead assertion. For example,
"/\w+(?=\t)/" matches a word followed by a tab, without including
the tab in $&.

Az.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top