Skip to content
Tcl Source Code View Ticket
Login

View Ticket

regexp behaviour differs based on passing option as literal v/s variable

Open7e4d5a0a2b439cd36db77d3a5d6a09cb5c4f8d7cCreated 11 years agoUpdated 53 days ago
Descriptionplain2016-05-20 13:10:13
As seen below regexp behaviour is different based on -nocase (or any option) being passed as literal or through a variable.

% set switch -nocase
-nocase
% regexp $switch "Looking for -nocase"
1
% regexp -nocase "Looking for -nocase"
wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"

dgp from chat:

dgp	I'd guess a compiler bug
[18:36]	dgp	% set cmd regexp
		regexp
		% set switch -nocase
		-nocase
		% $cmd $switch "Looking for -nocase"
		wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"
Referenced by1
  • 0b36adaf16Fix [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:29
serhiy.storchakawiki2026-10-11 07:39:52

Same cause as [1902890fff]. Proposed fix in branch regexp-compile-runtime-switch: compiled regexp $switch "Looking for -nocase" now gives "wrong # args", as the command does.

Log in (anonymous is fine) to add a comment.