Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England. PCRE stands for ``Perl-compatible regular expressions''. This manual only documents how Onyx interfaces with PCRE. For more information about how PCRE's regular expressions work, see the following:
For general information about Perl regular expressions, the following are recommended:
There are two special Onyx object types that support regular expressions: regex and regsub. Objects of these types are created via the regex and regsub operators, respectively. The match operator applies a regular expression to an input string, the submatch operator returns a matched substring of the input string, and the offset operator returns the offset of a substring match relative to the beginning of the input string. The split operator creates an array of substrings that are separated by strings that match a regular expression. The subst operator finds regular expression matches within an input string and applies a substitution template to the matches, thereby creating an output string. See Section 2.11.9 for detailed documentation on the above-mentioned operators.
Regular expressions are written as strings in Onyx, so all of the standard special sequences within strings are interpreted directly by the Onyx scanner. Note that the \ character is only special within strings if it is followed by a special sequence. This allows regular expressions to seamlessly extend the set of special sequences within strings while maintaining a reasonably consistent syntax.
The following sequences have special meaning within strings that specify substitution templates:
Sequence | Description |
\1..\9 | Refer to captured expressions 1 through 9. |