While template processors are typically a separate piece of software, used as part of a system or framework, simple templating languages are commonly included in the string processing features of
general-purpose programming languages, and in text processing programs, notably
text editors or
word processors. The templating languages are generally simple substitution-only languages, in contrast to the more sophisticated facilities in full-blown template processors, but may contain some logic. Simple examples include
‘printf’ print format strings, found in many programming languages, and
snippets, found in a number of text editors and
source code editors. In word processors,
templates are a common feature, while automatic filling in of the templates is often referred to as
mail merge. An illustrative example of the complementary nature of
parsing and templating is the s (substitute) command in the
sed text processor, originating from search-and-replace in the
ed text editor. Substitution commands are of the form s/regexp/replacement/, where regexp is a
regular expression, for parsing input, and replacement is a simple template for output, either literal text, or a format string containing the characters & for "entire match" or the special
escape sequences \1 through \9 for the
nth sub-expression. For example, s/(cat|dog)s?/\1s/g replaces all occurrences of "cat" or "dog" with "cats" or "dogs", without duplicating an existing "s": (cat|dog) is the 1st (and only) sub-expression in the regexp, and \1 in the format string substitutes this into the output. ==System elements==