Skip to content
Tcl Source Code Artifact [b1c39e3668]
Login

Artifact [b1c39e3668]

Artifact b1c39e3668d3642d3218fbed0560aed0ae73e694:

Ticket change [b1c39e3668] - New ticket [504785ffffffffff|504785ffff] <i>Match error with regexp</i>. by jkbonfield on 2002-01-17 09:36:12.
D 2002-01-17T09:36:12
J assignee nobody
J cmimetype text/plain
J comment In\ssome\scases\sregular\sexpressions\sseem\sto\smatch\sthe\nshortest\sstring\sinstead\sof\sthe\slongest\sstring.\sAs\nreported\sin\scomp.lang.tcl:\n\nAs\sreported\sin\scomp.lang.tcl\son\s16th\sJan\s2002:\n\ntclsh>puts\s$tcl_patchLevel\n7.4p2\ntclsh>regexp\s{([^_.]*)([^.]*)\\.(..)(.).*}\nbbcos_001_c01.q1la\s_\sm(1)\sm(2);\sparray\sm\nm(1)\s=\sbbcos\nm(2)\s=\s_001_c01\n\n(Correct)\n\n\n%\sputs\s$tcl_patchLevel\n8.3.1\n%\sregexp\s{([^_.]*)([^.]*)\\.(..)(.).*}\nbbcos_001_c01.q1la\s_\sm(1)\sm(2);\sparray\sm\nm(1)\s=\sc01\nm(2)\s=\s\n\nNow\sthe\sre_syntax\smanual\spage\sstates,\squite\srightly,\nthat\sexpressions\smatch\nthe\sfirst\sstring\sthey\sfind\sand\s(assuming\sdefault\narguments)\swill\sproceed\sto\ngobble\sup\sthe\smaximum\slength\sof\sinput.\n\nSo\s[^_.]*\sshould\sstart\sat\sthe\sbeginning\s("b")\sand\nextend\sup\sto\sthe\sfirst\nunderscore;\sie\s"bbcos".\sThe\sdot\sin\shere\sis\ssuperfluous,\nand\sremoving\sit\scures\nthe\s"problem",\sas\sdoes\sforcibly\sanchoring\sit\sto\sthe\nstart\sof\sthe\smatch:\n\n%\sputs\s$tcl_patchLevel\n8.3.1\n%\sregexp\s{([^_]*)([^.]*)\\.(..)(.).*}\sbbcos_001_c01.q1la\n_\sm(1)\sm(2);\sparray\sm\nm(1)\s=\sbbcos\nm(2)\s=\s_001_c01\n%\sregexp\s{^([^_.]*)([^.]*)\\.(..)(.).*}\nbbcos_001_c01.q1la\s_\sm(1)\sm(2);\sparray\sm\nm(1)\s=\sbbcos\nm(2)\s=\s_001_c01\n\n\nMichael\sCleverly\sposted\sa\suseful\sfollow\sup\soutlining\nthe\sresults\sfrom\sdifferent\stcl\sversions:\n\nLooks\slike\sa\sbug\sto\sme.\s\sGiven\syour\sfirst\sregular\nexpression,\sthese\sare\nthe\sresults\sI\sget:\n\n\s\s\s\sm(1)\s=\sbbcos\n\s\s\s\sm(2)\s=\s_001_c01\n\nwith\sTcl\s7.0,\s7.1,\s7.3,\s7.4,\s7.5,\s7.5p1,\s7.6,\s7.6p2,\n8.0,\s8.0p2,\s8.0.3,\n8.0.4,\sand\s8.0.5;\n\n\s\s\s\sm(1)\s=\n\s\s\s\sm(2)\s=\s_c01\n\nwith\sTcl\s8.1.0\sand\s8.1.1;\sand,\slast,\sbut\snot\sleast:\n\n\s\s\s\sm(1)\s=\sc01\n\s\s\s\sm(2)\s=\n\nwith\sTcl\s8.2.0,\s8.2.1,\s8.2.2,\s8.2.3,\s8.3.0,\s8.3.1,\n8.3.2,\s8.3.3,\s8.3.4,\n8.4a2,\sand\s8.4a3.\n\nYour\stwo\salternate\sregular\sexpressions,\sthat\sworked\sfor\nyou\sunder\sboth\s7.6\nand\s8.3\swork\sfine\son\sall\sthe\sabove\sversions\stoo,\sas\sdo\nthese\sadditional\nvariants:\n\nset\sRE4\s{([^_.]*)([^.]*)}\nset\sRE5\s{([^_.]+)([^.]*)\\.(..)(.).*}\nset\sRE6\s{([^_.]*)([^.]+)\\.(..)(.).*}\nset\sRE7\s{([^_.]*)([^.]*).(..)(.).*}\n\nIt\salmost\sseems\sas\sif\sbeginning\swith\sTcl\s8.1\sthe\sregex\nengine\sis\streating\nthe\sfirst\stwo\ssets\sof\sparenthesis\sas\snon-greedy\s&\sis\nlooking\sfor\sthe\nshortest\smatch,\sthough\s[regexp\s-about]\sdoesn't\sshow\nREG_USHORTEST.\n\n\n
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter jkbonfield
J subsystem 43.\sRegexp
J title Match\serror\swith\sregexp
J type Bug
K 504785ffffffffffffffffffffffffffffffffff
U jkbonfield
Z 35e27ed0bb02891a05d65ec971506c8c