The SPAN_REGEXP rule is similar to the SPAN rule except the start sequence and optionally the end sequence are taken to be regular expressions. In addition to the attributes supported by the SPAN tag, the following attributes are supported:

HASH_CHAR and HASH_CHARS attributes are both optional, but you may only specify one, not both. If both are specified, HASH_CHARS is ignored and an error is shown. Whenever possible, use a literal prefix to specify a SPAN_REGEXP. If the starting prefix is always the same, use HASH_CHAR and provide as much prefix as possible. Only in rare cases would you omit both attributes, such as the case where there is no other reliable way to get the highlighting you need, for example, with comments in the Cobol programming language.

In addition, the END subtag supports the attribute REGEXP, which if set to TRUE, tells the highlighter to interpret the END text as a regular expression as well.

The regular expression match cannot span more than one line. Any text matched by groups in the BEGIN regular expression is substituted in the END string. See below for an example of where this is useful.

Regular expression syntax is described in Appendix E, Regular Expressions.

Here is a SPAN_REGEXP rule that highlights read-ins in shell scripts:


Here is a SPAN_REGEXP rule that highlights constructs placed between <#ftl and >, as long as the <#ftl is followed by a word break: