CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 3394
content-type: text/html; charset=utf-8
last-modified: Sat, 11 Oct 2025 15:49:54 GMT
traceparent: 51e1581d017afa1281cd70e1c660a804
strict-transport-security: max-age=15768000
[perl #56526] m/a{1,0}/ compiles but doesn't match a literal string - nntp.perl.org
Front page | perl.perl5.porters |
Postings from July 2008
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About

[perl #56526] m/a{1,0}/ compiles but doesn't match a literal string
Thread NextFrom:
Michael CartmellDate:
July 2, 2008 07:30Subject:
[perl #56526] m/a{1,0}/ compiles but doesn't match a literal stringMessage ID:
rt-3.6.HEAD-27577-1215001078-1211.56526-75-0@perl.org# New Ticket Created by Michael Cartmell # Please include the string: [perl #56526] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=56526 > This is a bug report for perl from michael@lnx-main.cartmell.net, generated with the help of perlbug 1.36 running under perl 5.10.0. ----------------------------------------------------------------- The regular expression /a{2,1}/ fails to compiles the the error Can't do {n,m} with n > m in regex; marked by <-- HERE in m/a{2,1} <-- HERE / at -e line 1. The regular expression /a{2,-1}/ compiles and matches a literal "a{2,-1}". The regex /a{2,0}/, however, compiles into a form that must match at least two "a"s but then fails. I'm guessing because at the point it has matched two "a"s it must also match no more than zero. michael@lnx-main:perl-5.10.x> perl -Mre=debug -E'say "matched" if "aaa" =~ qr/a{2,0}/' Compiling REx "a{2,0}" Final program: 1: CURLY {2,0} (5) 3: EXACT <a> (0) 5: END (0) anchored "aa" at 0 (checking anchored) minlen 2 Guessing start of match in sv for REx "a{2,0}" against "aaa" Found anchored substr "aa" at offset 0... Guessed: match at offset 0 Matching REx "a{2,0}" against "aaa" 0 <> <aaa> | 1:CURLY {2,0}(5) failed... 1 <a> <aa> | 1:CURLY {2,0}(5) failed... Match failed Freeing REx: "a{2,0}" The choices appear to be 1. document this as the expected behaviour. 2. match a literal "a{2,0}", consistent with /a{2,-0}/. 3. make /a{2,0}/ an error, consistent with /a{2,1}/. This patch make /a{2,0}/ an error and adds a test. *** perl-5.10.x-orig/regcomp.c 2008-07-02 21:32:25.067518022 +1000 --- perl-5.10.x/regcomp.c 2008-07-02 18:19:28.371522116 +1000 *************** *** 6366,6372 **** *flagp = WORST; if (max > 0) *flagp |= HASWIDTH; ! if (max && max < min) vFAIL("Can't do {n,m} with n > m"); if (!SIZE_ONLY) { ARG1_SET(ret, (U16)min); --- 6366,6372 ---- *flagp = WORST; if (max > 0) *flagp |= HASWIDTH; ! if (max < min) vFAIL("Can't do {n,m} with n > m"); if (!SIZE_ONLY) { ARG1_SET(ret, (U16)min); *** perl-5.10.x-orig/t/op/re_tests 2008-07-02 21:32:18.867512251 +1000 --- perl-5.10.x/t/op/re_tests 2008-07-02 21:16:52.063549753 +1000 *************** *** 618,623 **** --- 618,624 ---- ((?>[^()]+)|\([^()]*\))+ ((abc(ade)ufh()()x y $& abc(ade)ufh()()x (?<=x+)y - c - Variable length lookbehind not implemented a{37,17} - c - Can't do {n,m} with n > m + a{37,0} - c - Can't do {n,m} with n > m \Z a\nb\n y $-[0] 3 \z a\nb\n y $-[0] 4 $ a\nb\n y $-[0] 3 Regards, Michael Cartmell ----------------------------------------------------------------- --- Flags: category=core severity=low --- Site configuration information for perl 5.10.0: Configured by michael at Fri Jun 27 15:55:25 EST 2008. Summary of my perl5 (revision 5 version 10 subversion 0 patch 34065) configuration: Platform: osname=linux, osvers=2.6.25.5-1.1-default, archname=i686-linux-64int-ld uname='linux lnx-main 2.6.25.5-1.1-default #1 smp 2008-06-07 01:55:22 +0200 i686 athlon i386 gnulinux ' config_args='' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=define usemymalloc=y, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -march=athlon-xp', cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.8.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.8' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -march=athlon-xp -L/usr/local/lib -fstack-protector' Locally applied patches: MAINT33535 --- @INC for perl 5.10.0: /net/perl/5.10.1-devel/lib/5.10.0/i686-linux-64int-ld /net/perl/5.10.1-devel/lib/5.10.0 /net/perl/5.10.1-devel/lib/site_perl/5.10.0/i686-linux-64int-ld /net/perl/5.10.1-devel/lib/site_perl/5.10.0 . --- Environment for perl 5.10.0: HOME=/home/michael LANG=en_GB.UTF-8 LANGUAGE= LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/net/perl/5.10.1-devel/bin:/home/michael/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin PERL_BADLANG (unset) SHELL=/bin/bashThread Next
- [perl #56526] m/a{1,0}/ compiles but doesn't match a literal string by Michael Cartmell
- Re: [perl #56526] m/a{1,0}/ compiles but doesn't match a literal string by Rafael Garcia-Suarez
- Re: [perl #56526] m/a{1,0}/ compiles but doesn't match a literal string by demerphq
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About