text...trim(3tcl)
π text...trim β aka the Text and string utilities, macro processing glow-up π
okay bestie, sit down, hydrate, because we're about to talk about textutil::trim, a whole package from the Text and string utilities, macro processing corner of the world that just... trims strings. With regexes. Iconic behavior honestly.
β¨ NAME β¨
textutil::trim β the procedures that trim strings π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require textutil::trim ?0.8?
::textutil::trim::trim string ?regexp?
::textutil::trim::trimleft string ?regexp?
::textutil::trim::trimright string ?regexp?
::textutil::trim::trimPrefix string prefix
::textutil::trim::trimEmptyHeading string
β¨ DESCRIPTION β¨
so the textutil::trim package hands you a bunch of commands that trim strings using arbitrary regular expressions. no cap. whatever regex you want, it'll trim with it.
and here's the full lineup of procedures, described one by one, because we do not skip anybody in this house π
::textutil::trim::trimstring ?regexp?
Removes from string any leading and trailing substring that matches the regular expression regexp, and returns the result as a brand new string. and this happens for all lines in the string β meaning any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline at all, between the beginning and the end of the string. the regexp defaults to "[ \t]+". yes really, that's the default, go off.
::textutil::trim::trimleftstring ?regexp?
Removes from string any leading substring that matches the regular expression regexp, and returns the result as a new string. this applies to any line in the string β any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline, between the beginning and the end of the string. the regexp defaults to "[ \t]+". left side only, she's selective like that π¦
::textutil::trim::trimrightstring ?regexp?
Removes from string any trailing substring that matches the regular expression regexp, and returns the result as a new string. this applies to any line in the string β any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline, between the beginning and the end of the string. the regexp defaults to "[ \t]+". right side only, she's the mirror twin β¨
::textutil::trim::trimPrefixstring prefix
Removes the prefix from the beginning of string and returns the result. and here's the key part, bestie: the string is left unchanged if it doesn't have prefix at its beginning. no prefix, no touch, we respect boundaries π
::textutil::trim::trimEmptyHeadingstring
Looks for empty lines (and yes, that includes lines consisting of only whitespace) at the beginning of the string and removes them. the modified string comes back as the result of the command. bye bye dead air at the top π«Ά
π BUGS, IDEAS, FEEDBACK π
not to be dramatic but: this document, and the package it describes, will undoubtedly contain bugs and other problems. the manpage said it, not me π
please report such things in the category textutil of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). and please also report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion.
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
also note, and this is important: attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. okay? okay. π
π SEE ALSO π
regexp(3tcl), split(3tcl), string(3tcl)
π KEYWORDS π
prefix, regular expression, string, trimming
ποΈ CATEGORY ποΈ
Text processing
and that's the whole page, no notes, we ate π
tcllib, version 0.8, and it's filed under text...trim(3tcl) β mwah, sending you off with a forehead kiss and a working regex π
β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms