[Top][All Lists]

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

[Octave-bug-tracker] [bug #41211] regexp: groups with '?' matching handl

From: Michael C. Grant
Subject: [Octave-bug-tracker] [bug #41211] regexp: groups with '?' matching handled different between matlab and octave
Date: Sun, 12 Jan 2014 21:00:15 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36


                 Summary: regexp: groups with '?' matching handled different
between matlab and octave
                 Project: GNU Octave
            Submitted by: mcgrant
            Submitted on: Sun 12 Jan 2014 09:00:15 PM GMT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Michael C. Grant
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any



If a grouping construct is followed by '?', and that group is not matched,
Octave does not return an entry for that token. MATLAB, however, returns an
empty string. 

At first I thought this is probably not important, and I've already fixed it
in my code. Indeed, MATLAB's behavior might be considered *wrong*, since the
empty string will in many cases not be a valid match. 

But here's an example where I think the Octave behavior could be potentially
problematic. In this case, the final grouping is returned as token #2 in
Octave, and token #3 in MATLAB. It seems to me that MATLAB's behavior is
better here. After all, is that second token returned by Octave from group 2
or group 3? To determine this, you would have to do additional tests.


octave:1> str = 'test::'
str = test::
octave:2> toks = regexp(str, '^([a-zA-Z]w*)((.*))?(.+)?$', 'tokens' )
toks = 
  [1,1] = 
    [1,1] = test
    [1,2] = ::


>> str = 'test::'
str =
>> toks = regexp(str, '^([a-zA-Z]w*)((.*))?(.+)?$', 'tokens' )
toks = 
    {1x3 cell}
>> toks{:}
ans = 
    'test'    ''    '::'


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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