D 2019-11-22T17:13:34.949
J icomment If\sthe\sissue\sis\s"caused"\sbecause\sRE-engine\sfollowing\smain\srule\s"greediness\sof\stopmost\sexpression\swins"\sor\slike\sa\sKevin's\sstatement:\r\n<blockquote><i>A\sgeneral\srule\sis\sthat\sthe\sgreediness\sof\sthe\soutermost\squantifier\sdetermines\sthe\sgreediness\sof\severything\sin\sthe\ssubexpression.</i></blockquote>\r\n\r\nit\scould\sexplain\swhy\sinitially\snon-greedy\ssubexpression\sgrows,\seven\sto\sfulfill\sthe\swhole\smatch\sbe\sgreedy.\r\n\r\nSo\sfor\sexample\shere\sthe\sfirst\scapturing\sgroup\sgrows\sto\swhole\smatch,\sthe\ssecond\s(inner)\sgroup\scapturing\s<b\sstyle="color:blue"><code>aaaf</code></b>\sand\s<b\sstyle="color:#A09"><code>aaf</code></b>\seach\safter\sother\s(so\sultimately\sgets\sthe\svalue\sof\sthe\slast\sone).\r\n<pre>\r\n\s\s\s\s%\sregexp\s-inline\s{((a*f)*?)<b>?</b>}\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\r\n\s\s\s\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\s<b\sstyle="color:#A09">aaf</b>\r\n</pre>\r\n\r\nBut\sthere\sis\sjust\sanother\sexample\sillustrating\sthat\sthis\s"concept"\sis\snot\scompletely\scorrect:\r\n\r\n<pre>\r\n\s\s\s\s%\sregexp\s-inline\s{((a*f)*?)<b\sstyle="color:green">*</b>}\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\r\n\s\s\s\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\s<b\sstyle="color:#A09">aaf</b>\s<b\sstyle="color:#A09">aaf</b>\r\n\s\s\s\s%\sregexp\s-inline\s{((a*f)*?)<b\sstyle="color:red">+</b>}\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\r\n\s\s\s\s<b\sstyle="color:blue">aaaf</b><b\sstyle="color:#A09">aaf</b>\s{}\s{}\r\n</pre>\r\n\r\nBoth\sof\stopmost\squantifiers\s(red/green)\sare\sgreedy,\sthe\swhole\sexpression\sis\sgreedy.<br/>\r\nThe\swhole\sresult\scorresponds\sgreedy\swhole\smatch\s(matches\sthe\swhole\sstring\sin\sboth\scases).<br/>\r\nBut\sin\sthe\ssecond\scase\sthe\sgroups\sare\sempty\s(so\sit\sis\ssomehow\snon-greedy\sanymore).<br/>\r\n\r\nSo\sthe\s(more\saggressive)\squantifier\s<code>+</code>\sbehaves\s<b>fewer</b>\sgreedy\sas\s(fewer\saggressive)\squantifier\s<code>*</code>\sinside\sthe\scapturing\sgroups.
J login sebres
J mimetype text/x-fossil-wiki
K 3574242fffffffffffffffffffffffffffffffff
U sebres
Z 96aa1026b7f546a13eb716bcd309c079