• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X Scripting - Skill
  3. How to use regular expressions in SKILL

Stats

  • Replies 0
  • Subscribers 18
  • Views 32
  • Members are here 0
More Content

How to use regular expressions in SKILL

SaiPavanl
SaiPavanl 1 day ago

Often, you need to match strings or symbols against a pattern. A regular expression is an object that describes a pattern of characters. Regular expressions are a way to match patterns with sequences of characters. They are used in every programming language like C++, Java, and Python. SKILL also provides a number of pattern-matching functions like rexMatchp, rexCompile, and rexExecute.

SKILL also supports pcreCompile and pcreExecute for Perl-Compatible Regular Expressions (PCRE).
 

rexMatchp

If you want to see whether the string matches a regular expression, you can use rexMatchp. For example, to check if a string has only numbers with a decimal point, you can use rexMatchp, as shown below:

Rules for constructing patterns or regular expressions are given later in this article.

Note: Here, the output of the SKILL command is shown after the => symbol:

rexMatchp("[0-9]*[.][0-9][0-9]*" "100.001")    => t

rexMatchp("[0-9]*[.][0-9]+" ".001")            => t

rexMatchp("[0-9]*[.][0-9]+" ".")               => nil

rexMatchp("[0-9]*[.][0-9][0-9]*" "10."          => nil

rexMatchp("[0-9" "100")

*Error* rexMatchp: Missing ] - "[0-9"

rexMatchp( t_pattern S_target ) 

This function matches S_target against the t_pattern regular expression and returns t if a match is found; otherwise, it returns nil.

An error occurs if the given pattern is ill-formed.
 

rexCompile and rexExecute

For greater efficiency when matching a number of targets against a single pattern, use the rexCompile and rexExecute functions. For example, if you need to work on nets that match a pattern, use rexCompile and rexExecute instead of using rexMatchp.

rexExecute matches a string or symbol against the previously compiled pattern that was set up by the last rexCompile call.

To check if the name of the nets that can be alphanumeric begins with alphabets, use the following command:

rexCompile("^[a-zA-Z][a-zA-Z0-9]*")    => t

rexExecute('Net123)                   => t

rexExecute("123 Nets")                => nil

Note: Calls to rexMatchp reset the pattern set up by rexCompile. If any calls to rexMatchP have been made, rexExecute will not match the pattern set by rexCompile.


PCRE 

The PCRE library provides functions for pattern matching using Perl-compatible regular expressions. For more details, refer to https://www.pcre.org.

pcreCompile compiles a regular expression string pattern(t_pattern) into an internal representation that you can use in a pcreExecute function call. The compilation method is PCRE or Perl-compatible. You can use a second (optional) argument to specify independent option bits for controlling the pattern compilation.

pcreCompile( 

t_pattern 

[ x_options ] 

) 

=> o_comPatObj / nil

For example, the [12[:^digit:]] PCRE pattern matches 1, 2, or any non-digit.

comPat1 = pcreCompile( "[12[:^digit:]]" ) => pcreobj@0x27d150 (Note that your object will be different)

pcreExecute( comPat1 "abc" )             => t 

pcreExecute( comPat1 "12a")   =>t

pcreExecute( comPat1 "3") =>nil

Here is another example:

comPat5 = pcreCompile( "^\\d?\\d(jan|feb|mar|apr|may|jun)\\d\\d$/" ) 

pcreExecute( comPat5 "25jun3" ) => nil

pcreExecute( comPat5 "25jun3" pcreGenExecOptBits(?anchored t) ) => nil

pcreExecute( comPat5 "25jun3" pcreGenExecOptBits(?partial t) ) => t 


Rules for constructing pattern or regular expressions

Regular expressions can contain both special and ordinary characters. Most ordinary characters, like 'A', 'a', or '0', are the simplest regular expressions; they simply match themselves. You can concatenate ordinary characters, so that last matches the 'last' string. There are also special symbols like *, +, and so on, which you can see in detail here:

\    General escape character with several uses

^    Assert start of the string (or line, in multi-line mode)

$    Assert end of the string (or line, in multi-line mode)

.  Match any character except new line (by default)

[    Start character class definition

|    Start of alternative branch

(   Start subpattern

)  End subpattern

?    Matches 0 or 1 quantifier

*   Matches 0 or more 

+   Matches 1 or more

The part of a pattern that is in square brackets is called a "character class". In a character class, the only metacharacters are:

\    General escape character

^    Negates the class, but only if the first character

-    Indicates character range

[   POSIX character class (only if followed by POSIX syntax)

]    Terminates the character class


Asterisk symbol (*)

While matching, it checks if the preceding character (or set of characters) repeats for 0 or more times (up to infinite).
Example: The ab*c regular expression matches with ac, abc, abbc, abbbc, and so on.


Plus symbol (+)

While matching, it checks if the preceding character (or set of characters) repeats for at least one or more times (up to infinite).
Example: The ab+c regular expression matches with abc, abbc, abbbc, and so on.


Wildcard (.)

The dot symbol can match any character; hence. it is called the wildcard character.
Example: The .* regular expression matches with any character any number of times.


Optional character (?)

While matching, the preceding character may or may not be present in the string to be matched.
Example: In docx?, the ? character tells the computer that x may or may not be present in the name of file format.


Caret symbol (^)

The match must start at the beginning of the string or line.
Example: ^abc matches abcd but not zabc.


Dollar symbol ($)

The match must occur at the end of the string or before \n at the end of the line or string.
Example: 333$ matches 901-333 but not 333-901

  • Cancel
  • Sign in to reply
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2026 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information