RosettaCodeData/Task/Strip-comments-from-a-string/Tcl/strip-comments-from-a-string-1.tcl
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

6 lines
335 B
Tcl

proc stripLineComments {inputString {commentChars ";#"}} {
# Switch the RE engine into line-respecting mode instead of the default whole-string mode
regsub -all -line "\[$commentChars\].*$" $inputString "" commentStripped
# Now strip the whitespace
regsub -all -line {^[ \t\r]*(.*\S)?[ \t\r]*$} $commentStripped {\1}
}