RosettaCodeData/Task/Strip-block-comments/Tcl/strip-block-comments-1.tcl
2023-07-01 13:44:08 -04:00

8 lines
399 B
Tcl

proc stripBlockComment {string {openDelimiter "/*"} {closeDelimiter "*/"}} {
# Convert the delimiters to REs by backslashing all non-alnum characters
set openAsRE [regsub -all {\W} $openDelimiter {\\&}]
set closeAsRE [regsub -all {\W} $closeDelimiter {\\&}]
# Now remove the blocks using a dynamic non-greedy regular expression
regsub -all "$openAsRE.*?$closeAsRE" $string ""
}