bugGNU Octave - Bugs: bug #56899, regexprep numbers groups...

 
 

bug #56899: regexprep numbers groups incorrectly

Submitter:  None
Submitted:  Sun 15 Sep 2019 01:37:53 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Duplicate Assigned to:  None
Originator Name:  Andrei Kramer Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.2
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 15 Sep 2019 07:56:01 PM UTC, comment #2: 

You are right! It probably is a duplicate.

Anonymous
Sun 15 Sep 2019 06:42:18 PM UTC, comment #1: 

Thank you for the clear bug report. I think this is related to or a duplicate of bug #38149, can you review the discussion there?

Mike Miller <mtmiller>
Group Member
Sun 15 Sep 2019 01:37:53 PM UTC, original submission:  

When a group/token is optional like this ()? the numbering of backreferences becomes unpredictable:


regexprep("abc","(a)(b)?(c)","$3,$2,$1")
ans = c,b,a
regexprep("ac","(a)(b)?(c)","$3,$2,$1")
ans = ,c,a
## expected result of the second variant:
c,,a


if (b)? doesn't match then $2 should be empty, instead the match of (c) becomes backreference $2.

When the pattern is drafted, it is unknown whether the optional group will match or not, so it's impossible to know how to write the replacement pattern (will c be $3 or $2?)

sed exhibits the expected behaviour.

echo -e "abc\nac" | sed -E 's/(a)(b)?(c)/\3,\2,\1/'
c,b,a
c,,a


Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by None (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-09-16 mtmiller StatusNone Duplicate
        Open/ClosedOpen Closed
        Dependencies- Depends on bugs #38149

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code