ZurĂĽck zur Liste

Inserting random text without any programming knowledge

To create dynamic parts of expansions (such as results of computations or random snippets), you can embed scripts in Typinator expansions. But there are many cool effects that you can produce without any programming knowledge, just by using Typinator’s built-in functions.

For example, assume you want to insert a random phrase in an expansion. This could be a greeting, a quotation, a random offer of your most popular products, and much more. You can produce such random text fragments with Typinator’s /Any function.

To insert an invocation of the function in an expansion, click the {…} pop-up and select “Any match” from the “Built-in Functions” submenu. As a result, you get the following template:

{/Any /pattern/text/}

“pattern” is a regular expression, and “text” is a longer text fragment. The function looks for all matches of the regular expression in the text and returns a random match. Here is a simple example for rolling dice:

{/Any /./123456/}

The period stands for any single character, so the pattern matches each of the six digits in the text. The /Any function now randomly selects one of the digits.

To return a whole word from a longer text, change the pattern to match a non-empty sequence of “word characters”. The regular expression \w stands for a word character (letter or digit), and the plus sign means a non-empty repetition of the previous expression. The following invocation returns one of the five animals:

{/Any /\w+/cat dog mouse elephant snake/}

For longer phrases, you can use the pattern .+, which stands for a non-empty sequence of arbitrary characters. By default, line breaks are not included in such sequences, so you can write your phrases in multiple lines. Here is an example that selects one of five quotes of Albert Einstein:

{/Any /.+/ Gravitation is not responsible for people falling in love. I never think of the future. It comes soon enough. Everything should be made as simple as possible, but not simpler. Imagination is more important than knowledge. Weakness of attitude becomes weakness of character. /}

You can take this one step further by including a text file containing your favorite quotes. For example, create a plain text file with one quote per line and put it into the “Text” subfolder in Typinator’s “Includes” folder. Then you can use the /Any function to select a random quote from the text file:

{/Any /.+/
{Text/FavoriteQuotes.txt}
/}