case foo { f(?=o)oo {} .* { echo fail 1 } } case foo { fo(?=x)o { echo fail 2 } .* { } } fun match { set res = $($1 $2) if [ $res != $3 ] { echo "match $1 $2: expected $3, got $res" } } fun x0 { case $1 { a(?=b). { echo yes } .* { echo no } } } match x0 aa no match x0 aaa no match x0 ab yes fun x1 { case $1 { a(?!x)x { echo yes } .* { echo no } } } match x1 a no match x1 aa no match x1 ax no match x1 axx no match x1 aax no