<i>can't force regex subexpression greediness as stated by man page</i>.
by
.
D 2019-05-12T18:45:58.744
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment The\sre_syntax\sman\spage\sstates\r\n\r\nThe\squantifiers\s\\fB{1,1}\\fR\sand\s\\fB{1,1}?\\fR\scan\sbe\sused\sto\r\nforce\slongest\sand\sshortest\spreference,\srespectively,\son\sa\r\nsubexpression\sor\sa\swhole\sRE.\r\n\r\nHowever,\sthis\sdoesn't\sactually\swork\sreliably,\sfor\sexample\r\n\r\n%\sregexp\s-inline\s{^(l*)(.*)(f*)$}\s{llmmmfff}\r\nllmmmfff\sll\smmmfff\s{}\r\n%\sregexp\s-inline\s{^(l*){1,1}?(.*)(f*)$}\s{llmmmfff}\r\nllmmmfff\sll\smmmfff\s{}\r\n\r\nThe\sfirst\sresult\sis\sfine,\sbut\sthe\ssecond\sresult\sshould\shave\sbeen\r\n\r\nllmmmfff\s{}\sllmmmfff\s{}\r\n\r\nthat\sis,\sthe\s(l*)\sshould\shave\sbeen\sforced\sto\sbe\snon-greedy.\r\n\r\nI\stracked\sthis\sdown\sto\san\sover-optimistic\soptimization\sin\sparseqatom():\r\nit\sthrows\saway\sa\s{1,1}\squantifier\swithout\sregard\sto\swhether\sit's\strying\sto\simpose\r\na\sdifferent\sgreediness\sthan\sthe\satom\swould\shave\snatively.\r\n\r\nThis\sseems\sto\sbe\ssufficient\sto\sfix\sit:\r\n\r\n@@\s-1155,7\s+1155,10\s@@\sparseqatom(struct\svars\s*v,\r\n\s\t\t/*\srest\sof\sbranch\scan\sbe\sstrung\sstarting\sfrom\satom->end\s*/\r\n\s\t\ts2\s=\satom->end;\r\n\s\t}\r\n-\telse\sif\s(m\s==\s1\s&&\sn\s==\s1)\r\n+\telse\sif\s(m\s==\s1\s&&\sn\s==\s1\s&&\r\n+\t\t\t\s(qprefer\s==\s0\s||\r\n+\t\t\t\s\s(atom->flags\s&\s(LONGER\s|\sSHORTER\s|\sMIXED))\s==\s0\s||\r\n+\t\t\t\s\sqprefer\s==\s(atom->flags\s&\s(LONGER\s|\sSHORTER\s|\sMIXED))))\r\n\s\t{\r\n\s\t\t/*\sno/vacuous\squantifier:\s\sdone\s*/\r\n\s\t\tEMPTYARC(s,\satom->begin);\t/*\sempty\sprefix\s*/\r\n\r\n(That's\sfrom\sa\sdraft\sPostgres\spatch,\syour\sformatting\sof\sthe\scode\sis\sdifferent)\r\n\r\nBTW,\sI\sthink\sthat\sthe\sweasel\swording\sin\sthe\sNOTE\sin\sre_syntax.n\simmediately\r\nafter\sthe\sabove-quoted\sbit\sis\sdue\sto\sthis\sbug.\r\n\r\nBackground\sat\r\nhttps://www.postgresql.org/message-id/flat/20583.1557680147%40sss.pgh.pa.us
J foundin 8.6.8
J is_private 0
J login tgl
J priority 5\sMedium
J private_contact 26864b65f1c6ce8bda86f87ed9c554e19ac0390d
J resolution None
J severity Minor
J status Open
J submitter tgl
J subsystem 43.\sRegexp
J title can't\sforce\sregex\ssubexpression\sgreediness\sas\sstated\sby\sman\spage
J type Bug
K 524b35a8b5f9ec643fc323582217193d91247430
U tgl
Z c8cd828b147d551b0217f13a4792462e