Index of /dev/null

Tagged: RegEx

AutoSmileys is an easy to use and highly customizable macro environment for Movable Type. It will replace self-defined text abbreviations by image tags when your site is published or dynamically rendered, respectively. It may be applied either within entries, comments, pages, or any other part of your site.

read article

While customizing my mt blog, I was wondering how to abbreviate long entry titles on particular places in a nice way. Well, mt provides template tag modifiers such as trim-to, but my aim was to do it more nicely, i.e. replacing anything behind the first three (or any other maximum) words by an ellipsis. For instance,

"more than three words"
should be shortened to
"more than three ..."
while a three-word-sentence should remain as it is.

The solution is a simple regex, of course. In Perl style,

s/ˆ(\S+(?:\s+\S+){2})(\s+\S+)+/$1 .../
does the job, because it doesn't match on three words or less. Equivalently, within mt template tags:
<$mt:EntryTitle regex_replace="/ˆ(\S+(?:\s+\S+){2})(\s+\S+)+/","$1&ensp;&hellip;"$>