bugGNU Octave - Bugs: bug #43649, strfind returns matches for empty...

 
 

bug #43649: strfind returns matches for empty pattern

Submitter:  Andreas Weber <andy1978>
Submitted:  Thu 20 Nov 2014 04:23:22 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.2 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 06 Dec 2014 06:19:04 AM UTC, comment #4: 

I changed strfind to be Matlab compatible in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/f054112912df).  Closing report.

Rik <rik5>
Group administrator
Thu 20 Nov 2014 11:16:10 PM UTC, comment #3: 

So, is the accepted wisdom that we should just change this for Matlab compatibility, despite the way most other programs handle this?

Incidentally, the regexp function has the option 'emptymatch' to decide which way to interpret an empty pattern.


octave:1> regexp ('foo', '', 'match')
ans = {}(1x0)
octave:2> regexp ('foo', '', 'match', 'emptymatch')
ans =
{
  [1,1] =
  [1,2] =
  [1,3] =
  [1,4] =
}


One way to look at this is that strfind is a Matlab function and they are free to define how it behaves, while regexp should be more compatible with generic regular expressions, which it is.

Rik <rik5>
Group administrator
Thu 20 Nov 2014 05:50:56 PM UTC, comment #2: 

It's explicitly noted in the "More About" section of

www.mathworks.com/help/matlab/ref/strfind.html

that a pattern of an empty string results in nothing being found. Might be worth specifically noting this case in our docstring also to avoid confusion.

Mike Miller <mtmiller>
Group Member
Thu 20 Nov 2014 05:43:34 PM UTC, comment #1: 



$ echo "foo" | grep ''
foo



>>> import re
>>> re.findall('', 'foo')
['', '', '', '']



Perl> my @m = "foo" =~ m//g;
4

Perl> foreach (@m) {print $_ . "h\n";}
h
h
h
h


I guess we will still need to fix this for Matlab compatibility though.

Carnë Draug <carandraug>
Group Member
Thu 20 Nov 2014 04:23:22 PM UTC, original submission:  

Octave 3.8.2 and default returns


octave:1> strfind ('foo', '')
ans =
   1   2   3   4


whereas MATLAB R2014a returns empty


>> strfind ('foo', '')
ans =
     []


which is more intuitive for me.

Andreas Weber <andy1978>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by andy1978 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-12-06 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-11-20 mtmiller CategoryNone Octave Function
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code