[Bug 242013] matching back references works only some of the time

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sat Nov 16 22:15:52 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242013

            Bug ID: 242013
           Summary: matching back references works only some of the time
           Product: Base System
           Version: 12.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: khellman at mcprogramming.com

Matching back references according to re_format(7):

     Finally, there is one new type of atom,
     a back reference: ‘\’ followed by a non-zero decimal digit d matches the
     same sequence of characters matched by the dth parenthesized
     subexpression (numbering subexpressions by the positions of their opening
     parentheses, left to right), so that (e.g.)  ‘\([bc]\)\1’ matches ‘bb’ or
     ‘cc’ but not ‘bc’.

does not always seem to work.  For instance, I would expect all of these 
to print the single input line:

$ echo '#20#20' | sed -n -E -e '/(#|0x)(..)\1\2/p'
$ echo '#2020#' | sed -n -E -e '/(#|0x)(..)\2\1/p'
$ echo '#202020' | sed -n -E -e '/(#|0x)(..)20\2/p'
#202020
$ echo '#202020' | sed -n -E -e '/(#|0x)(..)\2(20)/p'
$ echo '#202020' | sed -n -E -e '/(#|0x)(..)(20)\2/p'
#202020
$ echo '#202020' | sed -n -E -e '/(#|0x)(..)..\2/p'
#202020
$ echo '#20#20' | sed -n -E -e '/(#|0x)(..).\2/p'
#20#20

Additionally, gsed(1) equivalent invocations work as expected.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list