Next: 2.10 Object-oriented programming Up: 2. Onyx Language Reference Previous: 2.8 Memory management Contents Index

#
2.9 Regular expressions

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:

- The pcre(3) manual page.
- The official PCRE download site: `ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/`.
- The unofficial PCRE website: `http://www.pcre.org/`.

For general information about Perl regular expressions, the following are recommended:

- Perl 5.6.1 regular expression documentation: `http://www.perldoc.com/perl5.6.1/pod/perlre.html`.
- Mastering Regular Expressions, 2nd Ed., by Jeffrey E. F. Friedl. ISBN 0-596-00289-0.
- Perl 5 Pocket Reference, 3rd Ed., by Johan Vromans. ISBN 0-596-00032-4.
- Programming Perl, 3rd Ed., by Larry Wall, Tom Christiansen, and Jon Orwant. ISBN 0-596-00027-8.

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:

Table 2.3: Substitution template special characters
Sequence | Description
`\1..\9` | Refer to captured expressions 1 through 9.

Next: 2.10 Object-oriented programming Up: 2. Onyx Language Reference Previous: 2.8 Memory management Contents Index