bugGNU Octave - Bugs: bug #38149, regexp: doesn't return empty...

 
 

bug #38149: regexp: doesn't return empty tokens -- they just disappear

Submitted by:  None
Submitted on:  Wed 23 Jan 2013 10:55:06 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: In ProgressAssigned to: None
Originator Name: Originator Email: -unavailable-
Open/Closed: OpenRelease: 3.6.2
Operating System: Microsoft Windows

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Sun 07 Jul 2013 09:55:50 PM UTC, comment #15:

I've had a look at this and it is going to be much harder than I anticipated. I think a full re-write of Octave's interface with PCRE is required.

Rik <rik5>
Project Administrator
Fri 01 Feb 2013 06:04:40 PM UTC, comment #14:

Better, I'd say:

>> te = regexp ('abc', 'abc(z?)', 'tokenExtents');
>> celldisp (te)


te{1} =

4 3

>>
>> te = regexp ('abce', '((a)(z)?b(c)(z*))(z)?(e)?', 'tokenExtents');
>> celldisp (te)


te{1} =

1 3
4 3
4 4

>>
>> [T, TE, NM] = regexp (sprintf('%s','John Davis\nRogers, James'), '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens', 'tokenExtents', 'names');
>>
>> celldisp (T)


T{1}{1} =

John

T{1}{2} =

Davis

T{2}{1} =

nRogers

T{2}{2} =

James

>> celldisp (TE)


TE{1} =

1 4
6 10

TE{2} =

12 18
21 25

>> NM(1).first


ans =

John

>> NM(1).last


ans =

Davis

>> NM(2).first


ans =

James

>> NM(2).last


ans =

nRogers

>>

Michael Godfrey <godfrey>
Fri 01 Feb 2013 05:48:02 PM UTC, comment #13:

Okay, at least I got 1 out of 5 answers.

Let's try the following:

Rik <rik5>
Project Administrator
Fri 01 Feb 2013 05:25:25 PM UTC, comment #12:

Matlab is being a bit opaque, as usual:

>> version


ans =

7.9.0.529 (R2009b)

>> te = regexp ('abc', 'abc(z)?', 'tokenExtents');
>> typeinfo (te)

??? Undefined function or method 'typeinfo' for input arguments of type 'cell'.

>> celldisp (te)


te{1} =

4 3

>> te{:}


ans =

4 3

>> te[:]

??? te[:]
|
Error: Unbalanced or unexpected parenthesis or bracket.

Here is the result of "help disp" in Matlab:

>> help disp

DISP Display array.
DISP(X) displays the array, without printing the array name. In
all other ways it's the same as leaving the semicolon off an
expression except that empty arrays don't display.

If X is a string, the text is displayed.

=====================
This not quite the way disp() works in Octave, or actually
the way it seems to work in Matlab.

Michael Godfrey <godfrey>
Fri 01 Feb 2013 05:18:02 PM UTC, comment #11:

This is infuriating. How does one see the results of a calculation in Matlab? I don't understand why they are making it so difficult to print a data structure.

Let's try just one regexp until we can get it working.

Rik <rik5>
Project Administrator
Fri 01 Feb 2013 04:58:34 PM UTC, comment #10:

Oops. I cut and pasted from email.
Here is try from savannah
(with TE{:} at the end -- did not help)

>> [T, TE, NM] = regexp (sprintf('%s','John Davis\nRogers, James'), '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens', 'tokenExtents', 'names');
>> disp (T)

{1x2 cell} {1x2 cell}

>> disp (TE)

[2x2 double] [2x2 double]

>> disp (NM)

1x2 struct array with fields:
last
first

>>
>> te = regexp ('abce', '((a)(z)?b(c)(z*))(z)?(e)?', 'tokenExtents');
>> disp (te)

[3x2 double]

>>
>> [S, E, TE, M, T, NM, SP] = regexp ('abc', '(?<all>(a)(?<miss1>z?)b(?<hit1>c)(z*))')


S =

[]

E =

[]

TE =

{}

M =

{}

T =

{}

NM =

0x0 struct array with fields:
all

SP =

'abc'

>>
>> disp (TE)
>> disp (T)
>> disp (NM)
>>
>> TE{:}
>>

Michael Godfrey <godfrey>
Fri 01 Feb 2013 04:46:49 PM UTC, comment #9:

Michael,

Are you getting the test code from an e-mail, or cutting and pasting from the verbatim block on Savannah? The verbatim block in the bug report has lines that are longer than 80 characters. In the samples you ran it appears that Matlab is seeing only 80 characters at a time followed by a newline which is leading to bad input messages.

Maybe TE{:} will display the actual contents of the tokenExtents?

Rik <rik5>
Project Administrator
Fri 01 Feb 2013 04:39:22 PM UTC, comment #8:

Maybe this more explicit code will work.

well, does not look like it:

>> te = regexp ('abc', 'abc(z?)', 'tokenExtents');
>> disp (te)

[1x2 double]

>>
>> te = regexp ('abc', 'abc(z)?', 'tokenExtents');
>> disp (te)

[1x2 double]

>>
>> [T, TE, NM] = regexp (sprintf('%s','John Davis\nRogers, James'),

??? [T, TE, NM] = regexp (sprintf('%s','John Davis\nRogers, James'),
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

>> '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens',


ans =

(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)

ans =

tokens

>> 'tokenExtents', 'names');

??? 'tokenExtents', 'names');
|
Error: Unbalanced or unexpected parenthesis or bracket.

>> disp (T)

??? Undefined function or variable 'T'.

>> disp (TE)

??? Undefined function or variable 'TE'.

>> disp (NM)

??? Undefined function or variable 'NM'.

>>
>> te = regexp ('abce', '((a)(z)?b(c)(z*))(z)?(e)?', 'tokenExtents');
>> disp (te)

[3x2 double]

>>
>> [S, E, TE, M, T, NM, SP] = regexp ('abc',

??? [S, E, TE, M, T, NM, SP] = regexp ('abc',
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

>> '(?<all>(a)(?<miss1>z?)b(?<hit1>c)(z*))')

??? '(?<all>(a)(?<miss1>z?)b(?<hit1>c)(z*))')
|
Error: Unbalanced or unexpected parenthesis or bracket.

>>
>> disp (TE)

??? Undefined function or variable 'TE'.

>> disp (T)

??? Undefined function or variable 'T'.

>> disp (NM)

??? Undefined function or variable 'NM'.

>>
>>

Michael Godfrey <godfrey>
Fri 01 Feb 2013 04:11:52 PM UTC, comment #7:

Thanks Michael. I guess I don't know how to write Matlab code very well because I was expecting that it would actually print the matrix of tokenExtents rather than just declaring it to be a matrix.

Maybe this more explicit code will work.

Rik <rik5>
Project Administrator
Fri 01 Feb 2013 02:42:33 PM UTC, comment #6:

>> regexp ('abc', 'abc(z?)', 'tokenExtents')


ans =

[1x2 double]

>>
>> regexp ('abc', 'abc(z)?', 'tokenExtents')


ans =

[1x2 double]

>>
>> version


ans =

7.9.0.529 (R2009b)

>> t = regexp (sprintf('%s','John Davis\nRogers, James'), '(?<f.

??? t = regexp (sprintf('%s','John Davis\nRogers, James'), '(?<f.
|
Error: A MATLAB string constant is not terminated properly.

Michael Godfrey <godfrey>
Thu 31 Jan 2013 11:29:33 PM UTC, comment #5:

A fifth test I need run to see how Matlab is handling patterns which don't match in an alternation operator.

Rik <rik5>
Project Administrator
Thu 31 Jan 2013 05:30:35 PM UTC, comment #4:

I have one more set of regexp tests to run if you have the time.

Rik <rik5>
Project Administrator
Mon 28 Jan 2013 06:59:10 PM UTC, comment #3:

I have an implementation that works for tokens. Getting the tokenExtents to work correctly is more difficult. Could you run the following corner cases and tell me what Matlab returns?

Rik <rik5>
Project Administrator
Fri 25 Jan 2013 07:18:54 AM UTC, comment #2:

MATLAB (2011b):

>> [S, E, TE, M, T, NM, SP] = regexp ('bar2','^(foo)?bar(\d*)$')

S =
1
E =
4
TE =
[2x2 double]
M =
'bar2'
T =
{1x2 cell}
NM =
1x1 struct array with no fields.
SP =
'' ''

>> TE{:}

ans =
1 0
4 4

>> T{:}

ans =
'' '2'

>> [S, E, TE, M, T, NM, SP] = regexp ('bar2','^bar(z)?(\d*)$')

S =
1
E =
4
TE =
[2x2 double]
M =
'bar2'
T =
{1x2 cell}
NM =
1x1 struct array with no fields.
SP =
'' ''

>> TE{:}

ans =
4 3
4 4

>> T{:}

ans =
'' '2'

Anonymous
Thu 24 Jan 2013 10:38:22 PM UTC, comment #1:

This is confirmed on the development code branch as well.

For reference, could you try the following code bits on Matlab and post what it returns? I'm curious about how they handle token extents for matched but empty substrings which is where the issue lies.

Rik <rik5>
Project Administrator
Wed 23 Jan 2013 10:55:06 AM UTC, original submission:

Parenthesized subexpressions create tokens. If the subexpression matches an empty string, an empty string should be returned. Now they just disappear: If I have an expression with two parenthesized subexpressions and the first match empty, only the second token is returned. This is inconsistent with other regex implementations like perl and MATLAB.

This works:
t=regexp('1bar2','^(\d)bar(\d)$','tokens');
isequal(t{1}{2},'2')

This doesn't:
t=regexp('bar2','^(\d)bar(\d)$','tokens');
isequal(t{1}{2},'2')

t=regexp('bar2','^(foo)?bar(\d*)$','tokens');
isequal(t{1}{2},'2')

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -unavailable- added by mtmiller (Updated the item)
  • -unavailable- added by godfrey (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 12 Jan 2014 10:14:29 PM UTCrik5Dependencies-=>bugs #41211 is dependent
    Mon 28 Oct 2013 02:23:14 AM UTCmtmillerCategoryNone=>Octave Function
      Item GroupIncorrect Result=>Matlab Compatibility
    Sun 07 Jul 2013 09:55:50 PM UTCrik5Summaryregexp doesn\'t return empty tokens -- they just disappear=>regexp: doesn't return empty tokens -- they just disappear
    Mon 28 Jan 2013 06:59:38 PM UTCrik5StatusConfirmed=>In Progress
    Thu 24 Jan 2013 10:38:22 PM UTCrik5StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup