Posted to tcl by bairui at Wed Jul 18 07:41:16 GMT 2018view pretty

#!/usr/bin/env tclsh

set link {<a href='#8d33527478f37b5cabfc794734b8eb382e8d6396f1520247e97f82372b64b5c7'>&nbsp;&nbsp;&nbsp;'''http://www.magicsplat.com/blog/promises/%|%Making promises in Tcl%|%'''</a>}
set expected {<a href='#8d33527478f37b5cabfc794734b8eb382e8d6396f1520247e97f82372b64b5c7'>Making promises in Tcl</a>}

set matches [regexp -inline {>.*?(%\|%)(.*?)\1.*?<} $link]
set cleaned [regsub [string map {| \\|} [lindex $matches 0]] $link ">[lindex $matches 2]<"]

puts [format "Expected:\n%s\nGot:\n%s\n\n%s\n" $expected $cleaned [expr {$cleaned eq $expected ? "Woo hoo!" : "D'oh!"}]]