Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

rexCompile

rexCompile( 
t_pattern 
) 
=> t / nil 

Description

Compiles a regular expression string pattern into an internal representation to be used by succeeding calls to rexExecute.

This allows you to compile the pattern expression once using rexCompile and then match a number of targets using rexExecute; this gives better performance than using rexMatchp each time.

rexCompile does not support the extended regular expression syntax. To parse such regular expressions, you can use the pcre (Perl Compatible Regular Expressions) functions (such as pcreCompile) instead.

Arguments

t_pattern

Regular expression string pattern.

Value Returned

t

The given argument is a legal regular expression string.

nil

Signals an error if the given pattern is ill-formed or not a legal expression.

Examples

rexCompile("^[a-zA-Z]+")                
=> t
rexCompile("\\([a-z]+\\)\\.\\1")  
=> t
rexCompile("^\\([a-z]*\\)\\1$")  
=> t
rexCompile("[ab")
=> *Error* rexCompile: Missing ] - "[ab"

Pattern Matching of Regular Expressions

In many applications, you need to match strings or symbols against a pattern. SKILL provides a number of pattern matching functions that are built on a few primitive C library routines with a corresponding SKILL interface.

A pattern used in the pattern matching functions is a string indicating a regular expression. Here is a brief summary of the rules for constructing regular expressions in SKILL:

Rules for Constructing Regular Expressions
Synopsis Meaning

c

Any ordinary character (not a special character listed below) matches itself.

.

A dot matches any character.

\

A backslash when followed by a special character matches that character literally. When followed by one of <, >, (, ), and 1,...,9, it has a special meaning as described below.

[c...]

A nonempty string of characters enclosed in square brackets (called a set) matches one of the characters in the set. If the first character in the set is ^, it matches a character not in the set. A shorthand S-E is used to specify a set of characters S up to E, inclusive. The special characters ] and - have no special meaning if they appear as the first character in a set.

*

A regular expression of any of the forms above, followed by the closure character * matches zero or more occurrences of that form.

+

Similar to *, except it matches one or more times.

\(...\)

A regular expression wrapped as \( form \) matches whatever form matches, but saves the string matched in a numbered register (starting from one, can be up to nine) for later reference.

\n

A backslash followed by a digit n matches the contents of the nth register from the current regular expression.

\<...\>

A regular expression starting with a \< and/or ending with a \> restricts the pattern matching to the beginning and/or the end of a word. A word defined to be a character string can consist of letters, digits, and underscores.

rs

A composite regular expression rs matches the longest match of r followed by a match for s.

^, $

A ^ at the beginning of a regular expression matches the beginning of a string. A $ at the end matches the end of a string. Used elsewhere in the pattern, ^ and $ are treated as ordinary characters.

How Pattern Matching Works

The mechanism for pattern matching

The rexCompile function does the first part of the task, that is, the compilation of a pattern. The rexExecute function takes care of the second part, that is, matching a target against the previously compiled pattern. Sometimes this two-step interface is too low-level and awkward to use, so functions for higher-level abstraction (such as rexMatchp) are also provided in SKILL.

Avoiding Null and Backslash Problems

For example, to match a file name with dotted extension .il, the pattern "^[a-zA-Z]+\\.il$" can be used, but "^[a-zA-Z]\.il$" gives a syntax error. However, if the pattern string is read in from an input function such as gets that does not interpret backslash characters specifically, you should not add an extra backslash to enter a backslash character.

Related Topics

String Functions

rexExecute

rexMatchp

rexSubstitute

pcreCompile


Return to top
 ⠀
X