octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #56899] regexprep numbers groups incorrectly


From: anonymous
Subject: [Octave-bug-tracker] [bug #56899] regexprep numbers groups incorrectly
Date: Sun, 15 Sep 2019 09:37:54 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0

URL:
  <https://savannah.gnu.org/bugs/?56899>

                 Summary: regexprep numbers groups incorrectly
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sun 15 Sep 2019 01:37:53 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Andrei Kramer
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.2
        Operating System: GNU/Linux

    _______________________________________________________

Details:

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






    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56899>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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