regex compilation issue with (?q)
Closed / Invalid860549ba83b43dbe58ae9fd73e7d7a0c26f695b3Created 7 years agoUpdated 42 days ago
Descriptionplain2019-11-22 16:20:18
bll-tecra:bll$ rlwrap ../linux/64/tcl/bin/tclsh
% set pat "^(?q)/home/bll/blah/blah/blah"
^(?q)/home/bll/blah/blah/blah
% set fn "/home/bll/blah/blah/blah/somedir/somefile.txt"
/home/bll/blah/blah/blah/somedir/somefile.txt
% regsub $pat $fn {} stuff
couldn't compile regular expression pattern: quantifier operand invalid
%
Occurs in 8.6.9 also.
serhiy.storchakawiki2026-10-11 11:00:11
As re_syntax(n) says, embedded options such as (?q) are available only
at the start of an ARE. After ^, (? is parsed as a group
starting with a ? quantifier, hence the error; PostgreSQL (same engine)
rejects it the same way. (?q) also makes the rest of the RE literal, so it
cannot be combined with ^, and scoped forms like (?q:...)
are not supported. For an anchored literal prefix use
string first $prefix $fn == 0, or escape the prefix:
regexp ^[regsub -all {\W} $prefix {\\&}] $fn.
serhiy.storchaka Closed ticket [860549ba83].
[History diff]2026-10-11 11:00:11
serhiy.storchaka Ticket [860549ba83]: 3 changes
[History diff]2026-10-22 17:19:24
Log in (anonymous is fine) to add a comment.