The SPAN_REGEXP
rule is similar to the
SPAN
rule except the start sequence is taken to be a
regular expression. In addition to the attributes supported by the
SPAN
tag, the following attributes are
supported:
HASH_CHAR
- a literal string which must
be at the start of a regular expression.
HASH_CHARS
- a list of possible literal
characters, one of which must match at the start of the regular
expression.
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.
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:
<SPAN_REGEXP HASH_CHAR="<" TYPE="LITERAL1" DELEGATE="LITERAL"> <BEGIN><![CDATA[<<[\p{Space}'"]*([\p{Alnum}_]+)[\p{Space}'"]*]]></BEGIN> <END>$1</END> </SPAN_REGEXP>
Here is a SPAN_REGEXP
rule that highlights
constructs placed between <#ftl
and
>
, as long as the <#ftl
is
followed by a word break:
<SPAN_REGEXP TYPE="KEYWORD1" HASH_CHAR="<" DELEGATE="EXPRESSION"> <BEGIN><#ftl\b</BEGIN> <END>></END> </SPAN_REGEXP>