1 # Commands covered: regexp, regsub
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1998 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: regexp.test,v 1.30.2.1 2008/08/21 23:19:06 hobbs Exp $
16 source [file dirname [info script]]/testing.tcl
19 testConstraint regexp_are [regexp {\d} 1]
22 test regexp-1.1 {basic regexp operation} {
25 test regexp-1.2 {basic regexp operation} {
28 test regexp-1.3 {basic regexp operation} {
31 test regexp-1.4 {basic regexp operation} {
32 regexp -- -gorp abc-gorpxxx
34 test regexp-1.5 {basic regexp operation} {
35 regexp {^([^ ]*)[ ]*([^ ]*)} "" a
37 test regexp-1.6 {basic regexp operation} regexp_are {
38 list [catch {regexp {} abc} msg] $msg
40 #test regexp-1.7 {regexp utf compliance} {
41 # # if not UTF-8 aware, result is "0 1"
43 # regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
44 # list [string compare $foo $bar] [regexp 4 $bar]
48 test regexp-2.1 {getting substrings back from regexp} {
50 list [regexp ab*c abbbbc foo] $foo
52 test regexp-2.2 {getting substrings back from regexp} {
55 list [regexp a(b*)c abbbbc foo f2] $foo $f2
57 test regexp-2.3 {getting substrings back from regexp} {
60 list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
62 test regexp-2.4 {getting substrings back from regexp} {
66 list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
68 test regexp-2.5 {getting substrings back from regexp} {
69 set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
70 set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
71 list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
72 12223345556789999aabbb \
73 foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
74 $f6 $f7 $f8 $f9 $fa $fb
75 } {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
76 test regexp-2.6 {getting substrings back from regexp} {
77 set foo 2; set f2 2; set f3 2; set f4 2
78 list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
80 test regexp-2.7 {getting substrings back from regexp} {
81 set foo 1; set f2 1; set f3 1; set f4 1
82 list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
84 test regexp-2.8 {getting substrings back from regexp} {
86 list [regexp {^a*b} aaaab match] $match
88 test regexp-2.9 {getting substrings back from regexp} {
91 list [regexp f\352te(b*)c f\352tebbbbc foo f2] $foo $f2
92 } [list 1 f\352tebbbbc bbbb]
93 test regexp-2.10 {getting substrings back from regexp} {
96 list [regexp f\352te(b*)c eff\352tebbbbc foo f2] $foo $f2
97 } [list 1 f\352tebbbbc bbbb]
99 test regexp-3.1 {-indices option to regexp} {
101 list [regexp -indices ab*c abbbbc foo] $foo
103 test regexp-3.2 {-indices option to regexp} {
106 list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
108 test regexp-3.3 {-indices option to regexp} {
111 list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
113 test regexp-3.4 {-indices option to regexp} {
117 list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
118 } {1 {0 5} {1 4} {5 5}}
119 test regexp-3.5 {-indices option to regexp} {
120 set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
121 set f6 {}; set f7 {}; set f8 {}; set f9 {}
122 list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
124 foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
126 } {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
127 test regexp-3.6 {getting substrings back from regexp} {
128 set foo 2; set f2 2; set f3 2; set f4 2
129 list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
130 } {1 {1 1} {1 1} {-1 -1} {-1 -1}}
131 test regexp-3.7 {getting substrings back from regexp} {
132 set foo 1; set f2 1; set f3 1; set f4 1
133 list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
134 } {1 {1 2} {1 1} {-1 -1} {2 2}}
136 test regexp-4.1 {-nocase option to regexp} {
137 regexp -nocase foo abcFOo
139 test regexp-4.2 {-nocase option to regexp} {
143 list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
144 } {1 aBbbxYXxxZ Bbb xYXxx}
145 test regexp-4.3 {-nocase option to regexp} {
146 regexp -nocase FOo abcFOo
148 set x abcdefghijklmnopqrstuvwxyz1234567890
149 set x $x$x$x$x$x$x$x$x$x$x$x$x
150 test regexp-4.4 {case conversion in regexp} {
151 list [regexp -nocase $x $x foo] $foo
155 test regexp-5.1 {exercise cache of compiled expressions} {
163 test regexp-5.2 {exercise cache of compiled expressions} {
171 test regexp-5.3 {exercise cache of compiled expressions} {
179 test regexp-5.4 {exercise cache of compiled expressions} {
187 test regexp-5.5 {exercise cache of compiled expressions} {
196 test regexp-6.1 {regexp errors} {
197 list [catch {regexp a} msg] $msg
198 } {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
199 test regexp-6.2 {regexp errors} {
200 list [catch {regexp -nocase a} msg] $msg
201 } {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
202 test regexp-6.3 {regexp errors} jim {
203 list [catch {regexp -gorp a} msg] $msg
204 } {1 {bad switch "-gorp": must be --, -all, -indices, -inline, -line, -nocase, or -start}}
205 test regexp-6.4 {regexp errors} {
206 catch {regexp a( b} msg
208 test regexp-6.5 {regexp errors} regexp_are {
209 list [catch {regexp a) b} msg] [string match *parentheses* $msg]
211 test regexp-6.6 {regexp errors} {
212 list [catch {regexp a a f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1} msg] $msg
214 test regexp-6.7 {regexp errors} {
215 list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
217 test regexp-6.8 {regexp errors} jim {
220 list [catch {regexp abc abc f1(f2)} msg] $msg
221 } {1 {can't set "f1(f2)": variable isn't array}}
222 test regexp-6.9 {regexp errors, -start bad int check} {
223 list [catch {regexp -start bogus {^$} {}} msg] $msg
224 } {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
226 test regexp-7.1 {basic regsub operation} {
227 list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
228 } {1 xax111aaa222xaa}
229 test regexp-7.2 {basic regsub operation} {
230 list [regsub aa+ aaaxaa &111 foo] $foo
232 test regexp-7.3 {basic regsub operation} {
233 list [regsub aa+ xaxaaa 111& foo] $foo
235 test regexp-7.4 {basic regsub operation} {
236 list [regsub aa+ aaa 11&2&333 foo] $foo
238 test regexp-7.5 {basic regsub operation} {
239 list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
240 } {1 xaxaaa2aaa333xaa}
241 test regexp-7.6 {basic regsub operation} {
242 list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
243 } {1 xax1aaa22aaaxaa}
244 test regexp-7.7 {basic regsub operation} {
245 list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
247 test regexp-7.8 {basic regsub operation} {
248 list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
249 } "1 {xax1\\aa22aaxaa}"
250 test regexp-7.9 {basic regsub operation} {
251 list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
252 } "1 {xax1\\122aaxaa}"
253 test regexp-7.10 {basic regsub operation} {
254 list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
255 } "1 {xax1\\aaaaaxaa}"
256 test regexp-7.11 {basic regsub operation} {
257 list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
259 test regexp-7.12 {basic regsub operation} {
260 list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
261 } {1 xaxaaaaaaaaaaaaaaxaa}
262 test regexp-7.13 {basic regsub operation} {
264 list [regsub abc xyz 111 foo] $foo
266 test regexp-7.14 {basic regsub operation} {
268 list [regsub ^ xyz "111 " foo] $foo
270 test regexp-7.15 {basic regsub operation} {
272 list [regsub -- -foo abc-foodef "111 " foo] $foo
274 test regexp-7.16 {basic regsub operation} {
276 list [regsub x "" y foo] $foo
278 #test regexp-7.17 {regsub utf compliance} {
279 # # if not UTF-8 aware, result is "0 1"
280 # set foo "xyz555ijka\u4e4ebpqr"
281 # regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
282 # list [string compare $foo $bar] [regexp 4 $bar]
285 test regexp-8.1 {case conversion in regsub} {
286 list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
288 test regexp-8.2 {case conversion in regsub} {
289 list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
291 test regexp-8.3 {case conversion in regsub} {
293 list [regsub a(a+) xaAAaAAay & foo] $foo
295 test regexp-8.4 {case conversion in regsub} {
297 list [regsub -nocase a CaDE b foo] $foo
299 test regexp-8.5 {case conversion in regsub} {
301 list [regsub -nocase XYZ CxYzD b foo] $foo
303 test regexp-8.6 {case conversion in regsub} {
304 set x abcdefghijklmnopqrstuvwxyz1234567890
305 set x $x$x$x$x$x$x$x$x$x$x$x$x
307 list [regsub -nocase $x $x b foo] $foo
310 test regexp-9.1 {-all option to regsub} {
312 list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
313 } {4 a|xxx|b|xx|c|x|d|x|}
314 test regexp-9.2 {-all option to regsub} {
316 list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
317 } {4 a|XxX|b|xx|c|X|d|x|}
318 test regexp-9.3 {-all option to regsub} {
320 list [regsub x+ axxxbxxcxdx |&| foo] $foo
322 test regexp-9.4 {-all option to regsub} {
324 list [regsub -all bc axxxbxxcxdx |&| foo] $foo
326 test regexp-9.5 {-all option to regsub} {
328 list [regsub -all node "node node more" yy foo] $foo
330 test regexp-9.6 {-all option to regsub} {
332 list [regsub -all ^ xxx 123 foo] $foo
335 test regexp-10.2 {newline sensitivity in regsub} {
337 list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
339 test regexp-10.3 {newline sensitivity in regsub} {
341 list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
342 } "1 {dabc\n123\nxb}"
343 #test regexp-10.4 {partial newline sensitivity in regsub} {
345 # list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
347 #test regexp-10.5 {inverse partial newline sensitivity in regsub} {
349 # list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
350 #} "1 {da\nb123\nxb}"
352 test regexp-11.1 {regsub errors} {
353 list [catch {regsub a b} msg] $msg
354 } {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
355 test regexp-11.2 {regsub errors} {
356 list [catch {regsub -nocase a b} msg] $msg
357 } {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
358 test regexp-11.3 {regsub errors} {
359 list [catch {regsub -nocase -all a b} msg] $msg
360 } {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
361 test regexp-11.4 {regsub errors} {
362 list [catch {regsub a b c d e f} msg] $msg
363 } {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
364 test regexp-11.5 {regsub errors} jim {
365 list [catch {regsub -gorp a b c} msg] $msg
366 } {1 {bad switch "-gorp": must be --, -all, -line, -nocase, or -start}}
367 test regexp-11.6 {regsub errors} {
368 catch {regsub -nocase a( b c d} msg
370 test regexp-11.7 {regsub errors} jim {
373 list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
374 } {1 {can't set "f1(f2)": variable isn't array}}
375 test regexp-11.8 {regsub errors, -start bad int check} {
376 list [catch {regsub -start bogus pattern string rep var} msg] $msg
377 } {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
378 test regexp-11.9 {regsub without final variable name returns value} {
381 test regexp-11.10 {regsub without final variable name returns value} {
382 regsub -all a abaca X
385 test regexp-11.11 {regsub without final variable name returns value} {
386 regsub b(\[^d\]*)d abcdeabcfde {,&,\1,}
388 test regexp-11.12 {regsub without final variable name returns value} {
389 regsub -all b(\[^d\]*)d abcdeabcfde {,&,\1,}
390 } {a,bcd,c,ea,bcfd,cf,e}
392 # This test crashes on the Mac unless you increase the Stack Space to about 1
393 # Meg. This is probably bigger than most users want...
394 # 8.2.3 regexp reduced stack space requirements, but this should be
396 test regexp-12.1 {Tcl_RegExpExec: large number of subexpressions} {
397 list [regexp (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) abcdefghijklmnopqrstuvwxyz all a b c d e f g h i j k l m n o p q r s t u v w x y z] $all $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z
398 } {1 abcdefghijklmnopqrstuvwxyz a b c d e f g h i j k l m n o p q r s t u v w x y z}
400 test regexp-13.1 {regsub of a very large string} {
401 # This test is designed to stress the memory subsystem in order
402 # to catch Bug #933. It only fails if the Tcl memory allocator
405 set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
406 set filedata [string repeat $line 200]
407 for {set i 1} {$i<10} {incr i} {
408 regsub -all "BEGIN_TABLE " $filedata "" newfiledata
413 test regexp-14.1 {CompileRegexp: regexp cache} {
423 test regexp-14.2 {CompileRegexp: regexp cache, different flags} {
431 regexp -nocase $x bbba
434 test regexp-15.1 {regexp -start} regexp_are {
436 list [regexp -start -10 {\d} 1abc2de3 x] $x
438 test regexp-15.2 {regexp -start} regexp_are {
440 list [regexp -start 2 {\d} 1abc2de3 x] $x
442 test regexp-15.3 {regexp -start} regexp_are {
444 list [regexp -start 4 {\d} 1abc2de3 x] $x
446 test regexp-15.4 {regexp -start} regexp_are {
448 list [regexp -start 5 {\d} 1abc2de3 x] $x
450 test regexp-15.5 {regexp -start, over end of string} regexp_are {
452 list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
454 test regexp-15.6 {regexp -start, loss of ^$ behavior} {
455 list [regexp -start 2 {^$} {}]
457 test regexp-15.7 {regexp -start, double option} {
458 regexp -start 2 -start 0 a abc
460 test regexp-15.8 {regexp -start, double option} {
461 regexp -start 0 -start 2 a abc
463 test regexp-15.9 {regexp -start, end relative index} {
465 list [regexp -start end {\d} 1abc2de3 x] [info exists x]
467 test regexp-15.10 {regexp -start, end relative index} regexp_are {
469 list [regexp -start end-1 {\d} 1abc2de3 x] [info exists x] $x
472 test regexp-16.1 {regsub -start} regexp_are {
474 list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
476 test regexp-16.2 {regsub -start} {
478 list [regsub -all -start -25 {z} hello {/&} x] $x
480 test regexp-16.3 {regsub -start} {
482 list [regsub -all -start 3 {z} hello {/&} x] $x
484 #test regexp-16.4 {regsub -start, \A behavior} {
486 # lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
487 # lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
488 #} {5 /a/b/c/d/e 3 ab/c/d/e}
489 test regexp-16.5 {regsub -start, double option} {
490 list [regsub -start 2 -start 0 a abc c x] $x
492 test regexp-16.6 {regsub -start, double option} {
493 list [regsub -start 0 -start 2 a abc c x] $x
495 test regexp-16.7 {regexp -start, end relative index} {
496 list [regsub -start end a aaa b x] $x
498 test regexp-16.8 {regexp -start, end relative index} {
499 list [regsub -start end-1 a aaa b x] $x
502 test regexp-17.1 {regexp -inline} {
503 regexp -inline b ababa
505 test regexp-17.2 {regexp -inline} {
506 regexp -inline (b) ababa
508 test regexp-17.3 {regexp -inline -indices} {
509 regexp -inline -indices (b) ababa
511 test regexp-17.4 {regexp -inline} regexp_are {
512 regexp -inline {\w(\d+)\w} " hello 23 there456def "
514 test regexp-17.5 {regexp -inline no matches} {
515 regexp -inline {\w(\d+)\w} ""
517 test regexp-17.6 {regexp -inline no matches} {
518 regexp -inline hello goodbye
520 test regexp-17.7 {regexp -inline, no matchvars allowed} {
521 list [catch {regexp -inline b abc match} msg] $msg
522 } {1 {regexp match variables not allowed when using -inline}}
523 test regexp-17.8 {\W, \S and \D} regexp_are {
524 regexp -inline {(\W+)(\D+)(\S+)} " #!word abc 13123 "
525 } {{ #!word abc 13123} { #!} {word abc } 13123}
527 test regexp-18.1 {regexp -all} {
530 test regexp-18.2 {regexp -all} {
531 regexp -all b abababbabaaaaaaaaaab
533 test regexp-18.3 {regexp -all -inline} {
534 regexp -all -inline b abababbabaaaaaaaaaab
536 test regexp-18.4 {regexp -all -inline} regexp_are {
537 regexp -all -inline {\w(\w)} abcdefg
539 test regexp-18.5 {regexp -all -inline} regexp_are {
540 regexp -all -inline {\w(\w)$} abcdefg
542 test regexp-18.6 {regexp -all -inline} regexp_are {
543 regexp -all -inline {\d+} 10:20:30:40
545 test regexp-18.7 {regexp -all -inline} {
546 list [catch {regexp -all -inline b abc match} msg] $msg
547 } {1 {regexp match variables not allowed when using -inline}}
548 test regexp-18.8 {regexp -all} {
549 # This should not cause an infinite loop
550 regexp -all -inline {a*} a
552 test regexp-18.9 {regexp -all} {
553 # Yes, the expected result is {a {}}. Here's why:
554 # Start at index 0; a* matches the "a" there then stops.
555 # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
556 # that a* matches zero or more "a"'s; thus it matches the string "b", as
557 # there are zero or more "a"'s there.
558 # Go to index 2; this is past the end of the string, so stop.
559 regexp -all -inline {a*} ab
561 test regexp-18.10 {regexp -all} {
562 # Yes, the expected result is {a {} a}. Here's why:
563 # Start at index 0; a* matches the "a" there then stops.
564 # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
565 # that a* matches zero or more "a"'s; thus it matches the string "b", as
566 # there are zero or more "a"'s there.
567 # Go to index 2; a* matches the "a" there then stops.
568 # Go to index 3; this is past the end of the string, so stop.
569 regexp -all -inline {a*} aba
571 test regexp-18.11 {regexp -all} {
572 regexp -all -inline {^a} aaaa
574 test regexp-18.12 {regexp -all -inline -indices} {
575 regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
576 } {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
578 test regexp-19.1 {regsub null replacement} {
579 regsub -all {@} {@hel@lo@} "\0a\0" result
580 list $result [string length $result]
581 } "\0a\0hel\0a\0lo\0a\0 14"
583 #test regexp-20.1 {regsub shared object shimmering} {
585 # set a abcdefghijklmnopqurstuvwxyz
587 # set c abcdefghijklmnopqurstuvwxyz0123456789
589 # list $d [string length $d] [string bytelength $d]
590 #} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
591 #test regexp-20.2 {regsub shared object shimmering with -about} {
592 # eval regexp -about abc
595 test regexp-21.1 {regsub works with empty string} {
599 test regexp-21.2 {regsub works with empty string} {
603 test regexp-21.3 {regsub works with empty string offset} {
604 regsub -start 0 -- ^ {} foo
607 test regexp-21.4 {regsub works with empty string offset} {
608 regsub -start 0 -- \$ {} foo
611 test regexp-21.5 {regsub works with empty string offset} {
612 regsub -start 3 -- \$ {123} foo
615 test regexp-21.6 {regexp works with empty string} {
619 test regexp-21.7 {regexp works with empty string} {
620 regexp -start 0 -- ^ {}
623 test regexp-21.8 {regexp works with empty string offset} {
624 regexp -start 3 -- ^ {123}
627 test regexp-21.9 {regexp works with empty string offset} {
628 regexp -start 3 -- \$ {123}
631 #test regexp-21.10 {multiple matches handle newlines} {
632 # regsub -all -lineanchor -- {^#[^\n]*\n} "#one\n#two\n#three\n" foo\n
635 test regexp-21.11 {multiple matches handle newlines} {
636 regsub -all -line -- ^ "a\nb\nc" \#
639 test regexp-21.12 {multiple matches handle newlines} {
640 regsub -all -line -- ^ "\n\n" \#
643 test regexp-21.13 {multiple matches handle newlines} {
644 regexp -all -inline -indices -line -- ^ "a\nb\nc"
645 } {{0 -1} {2 1} {4 3}}
647 test regexp-21.14 {Literal newline in pattern} {
648 regexp -all -inline "\n(\[ \t\]+)" "\n\t\t# This is a test"
651 test regexp-21.15 {Replace literal backslash} {
652 regsub -all <bs> {<bs>abc<bs>def} \\ value
656 # Tests resulting from bugs reported by users
657 test reg-31.1 {[[:xdigit:]] behaves correctly when followed by [[:space:]]} {
658 set str {2:::DebugWin32}
659 set re {([[:xdigit:]])([[:space:]]*)}
660 list [regexp $re $str match xdigit spaces] $match $xdigit $spaces
661 # Code used to produce {1 2:::DebugWin32 2 :::DebugWin32} !!!