octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: behavior of regexp ( ) function


From: David Bateman
Subject: Re: behavior of regexp ( ) function
Date: Wed, 28 Jan 2009 23:47:43 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Soren Hauberg wrote:
ons, 28 01 2009 kl. 21:20 +0100, skrev David Bateman:
John W. Eaton wrote:
I'm not sure whether this is a bug.  But it is apparently incompatible
behavior.  I don't know what the fix is, but I looked at the
octregexp_list function, and it is correctly matching the first "20"
and moving idx forward to 2 (the position of the next character in the
string).  But then the next call to pcre_exec is matching zero or more
of anything not TAB and returning a zero-length substring starting and
ending at idx == 2.  So then ovector[1] <= ovector[0] and execution
breaks out of the loop.
I no longer have easy to matlab so can someone run the commands

a = sprintf("20\t50\tcelcius\t80");
b = sprintf("20\t50\t\t80");
regexp(a, '[^\t]+', 'match')
regexp(b, '[^\t]+', 'match')
regexp(a, '[^\t]*', 'match')
regexp(b, '[^\t]*', 'match')

on matlab and send the results? Its not clear from your message John if the behavior described by Daniel is the right one.

a = sprintf('20\t50\tcelcius\t80');
b = sprintf('20\t50\t\t80');
regexp(a, '[^\t]+', 'match')

ans =
    '20'    '50'    'celcius'    '80'

regexp(b, '[^\t]+', 'match')

ans =
    '20'    '50'    '80'

regexp(a, '[^\t]*', 'match')

ans =
    '20'    '50'    'celcius'    '80'

regexp(b, '[^\t]*', 'match')

ans =
    '20'    '50'    '80'

Soren


Thanks Soren and Benjamin, I believe the attached patch will do the right thing though I'm not sure why PCRE wants to return a zero length match for a pattern like "[^\t]*". Best just to ignore such matches rather than make them abort the search for matches as the code previously did. Patch pushed and attached

D.


--
David Bateman                                address@hidden
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]