Skip to content

Regexp with recursive subpatterns matches incorrectly #18096

Closed
@t-a-k

Description

@t-a-k

Description

Regular expression with recursive subpatterns ((?PARNO)) matches incorrectly.

Steps to Reproduce

perl -wE '"a + b + (c + d)" =~ /^((\w|\((\s)*(?1)(?3)*\))(?:(?3)*\+(?3)*(?2))*)(?3)*\+/ or die; say $1'

Expected behavior

In this regular expression, $1 is expected to match a expression-like string with balanced parenthesis, and whole pattern is to match partial expression without the last (parenthesized in this example) term (a + b +).
So this one-liner should print a + b, but actually prints a + b + (c .

Perl configuration

Summary of my perl5 (revision 5 version 33 subversion 1) configuration:
  Commit id: eab86acb0400b955ce0cd22c53d66e84ec8f3b7d
  Platform:
    osname=linux
    osvers=4.19.0-9-686-pae
    archname=i686-linux
    uname='linux x41 4.19.0-9-686-pae #1 smp debian 4.19.118-2+deb10u1 (2020-06-07) i686 gnulinux '
    config_args='-d -Dusedevel'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=undef
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='8.3.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=4
    doublesize=8
    byteorder=1234
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=12
    longdblkind=3
    ivtype='long'
    ivsize=4
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=4
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/i686-linux-gnu/8/include-fixed /usr/include/i386-linux-gnu /usr/lib /lib/i386-linux-gnu /lib/../lib /usr/lib/i386-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.28.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.28'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Aug 28 2020 19:07:39
  @INC:
    /usr/local/lib/perl5/site_perl/5.33.1/i686-linux
    /usr/local/lib/perl5/site_perl/5.33.1
    /usr/local/lib/perl5/5.33.1/i686-linux
    /usr/local/lib/perl5/5.33.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions