Incorrect argument handling by [regexp]
Here are the results of six invocations of the "regexp" command.
They indicate incorrect argument handling.
% set str "a-z"
a-z
% regexp - $str; #1
bad option "-": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --
% regexp \- $str; #2
1
% regexp {-} $str; #3
bad option "-": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --
% regexp -\\ $str; #4
couldn't compile regular expression pattern: invalid escape \ sequence
% regexp \\- $str; #5
1
% set initstring "-"
-
% regexp $initstring $str; #6
1
%
This discussion thread at c.l.t. provides some clues:
https://groups.google.com/g/comp.lang.tcl/c/pbqqj8tcIUk
b40148c895Ticket [1902890fff] compiled regexp behaves differently status still Pending with 3 other changes ticket2026-11-18 18:27:58b0610ccd6fFix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in2026-11-18 18:21:5933b0599e53Fix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in2026-11-18 17:39:076e93204003Fix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in2026-10-14 09:26:560b36adaf16Fix [1902890]: compiled [regexp] did not treat an RE value starting with "-" as a switch, unlike the command. When the RE is not known at compile time and there is no --, check it at runtime and call [regexp] itself if it starts with "-". Also fixes [7e4d5a0a2b] and case #6 of [697b1bbfe3]. New tests regexpComp-25.1 to 25.7. check-in2026-10-11 07:35:29a64804ce70Fix cases #2 and #4 of [697b1bbfe3]: the bytecode compiler for [regexp] checked for a leading "-" only in simple words, so patterns like \- or -\\ were compiled instead of being reported as bad options. Check the value of any word known at compile time, as for [regsub]. Incompatible for compiled code relying on it; for the next feature release. New tests regexpComp-24.12 to 24.15. check-in2026-10-10 21:10:10
Still the same in 8.6, 9.0 and 9.1. Cases #1, #3 and #5 are correct: an argument starting with "-" is taken as an option unless it follows --. #2 and #4 differ from the command only in compiled code: the bytecode compiler checked for a leading "-" only in words without backslashes, so \- and -\\ were compiled as patterns. #6 (a pattern in a variable) is the same problem as [1902890fff].
Proposed fix for #2 and #4 in branch regexp-compile-dash-pattern: the compiler checks the value of any word known at compile time, as for regsub, so both now give "bad option" as in #1. Tests regexpComp-24.12 to 24.15.
Proposed fix for case #6 in branch regexp-compile-runtime-switch, see [1902890fff].
Backported to core-8-6-branch: [b0610ccd6f]. In 8.6, regexp \- a-z reports "bad option" instead of 9.0's "ambiguous option", compiled and uncompiled alike, so regexpComp-24.12 expects that.