• Home
  • :
  • Community
  • :
  • Blogs
  • :
  • PCB Design
  • :
  • BoardSurfers: Using Regular Expressions in Allegro SKIL…

PCB Design Blogs

  • Subscriptions

    Never miss a story from PCB Design. Subscribe for in-depth analysis and articles.

    Subscribe by email
  • More
  • Cancel
  • All Blog Categories
  • Breakfast Bytes
  • Cadence Academic Network
  • Cadence Support
  • Computational Fluid Dynamics
  • CFD(数値流体力学)
  • 中文技术专区
  • Custom IC Design
  • カスタムIC/ミックスシグナル
  • 定制IC芯片设计
  • Digital Implementation
  • Functional Verification
  • IC Packaging and SiP Design
  • In-Design Analysis
    • In-Design Analysis
    • Electromagnetic Analysis
    • Thermal Analysis
    • Signal and Power Integrity Analysis
    • RF/Microwave Design and Analysis
  • Life at Cadence
  • Mixed-Signal Design
  • PCB Design
  • PCB設計/ICパッケージ設計
  • PCB、IC封装:设计与仿真分析
  • PCB解析/ICパッケージ解析
  • RF Design
  • RF /マイクロ波設計
  • Signal and Power Integrity (PCB/IC Packaging)
  • Silicon Signoff
  • Solutions
  • Spotlight Taiwan
  • System Design and Verification
  • Tensilica and Design IP
  • The India Circuit
  • Whiteboard Wednesdays
  • Archive
    • Cadence on the Beat
    • Industry Insights
    • Logic Design
    • Low Power
    • The Design Chronicles
Sanjiv Bhatia
Sanjiv Bhatia
1 Sep 2021

BoardSurfers: Using Regular Expressions in Allegro SKILL

As a developer, you would have often used regular expressions, (\.[a-zA-Z]{2,3}), in your code to search, extract, or replace words in a string. Whether it is C++, Java, or Python, you can use regex in every programing language to match any character combination in a string, be it numbers, letters, spaces or punctuation.

A regular expression or regex is a sequence of characters that define a search pattern. It provides a powerful way to search and replace text strings. You can use regular expressions in Allegro SKILL code as well. In our previous blog post, we looked at how to use variables and stacks in SKILL code. Today’s blog post is about how you can use regex in SKILL code.

Allegro SKILL supports several regex functions, including rexMatchp, rexCompile, and rexExecute, which we will discuss in this blog. We will also cover some special characters for constructing a regular expression pattern.

rexMatchp 

The rexMatchp(t_pattern S_target) function checks if a string matches the given regular expression. It matches S_target against the regular expression t_pattern and returns t if a match is found otherwise it returns nil. You can use this function to check if a string contains only numbers and a decimal as illustrated in the following example:

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

In the example above, the command returns t as the string matches the regular expression. In the following example, the command returns nil as the string does not match the regular expression.

rexMatchp("[0-9]*[.][0-9][0-9]*" "10."

An error message is displayed if the regex pattern is not formed correctly with the missing characters in the regex.

rexCompile and rexExecute

To match several strings against a single pattern, use rexCompile. This command compiles a pattern expression and then matches the strings using the rexExecute function. For example, to check if the names of the nets in a design consist of alphanumeric characters starting with a letter, use the following commands:

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

rexExecute('Net123)                   => t

rexExecute("123 Nets")                => nil

Read on, as we look at some special characters that you must learn to use regex in SKILL.

Special Characters for SKILL Regex

Some characters have a special significance in constructing a regex pattern in SKILL. A regex can contain any alphanumeric character, such as A, a, or 0; or special characters, such as * and +. The following table briefly explains the significance of special characters supported in a regex.

\

Use a backslash followed by a special character to match that character literally.

.

Matches any single character except the end of the line.

*

A regular expression followed by an asterisk matches zero or more occurrences.

+

Similar to an asterisk, a regex followed by a plus sign matches one or more occurrences of a character. For example, co+l matches col, cool, and cooool.

[ ]

Matches any single character enclosed within the bracketed list. For example, the regex b[aeo]d matches bad, bed, and bod.

( )

Groups one or more regular expressions. For example, (jan|feb|mar|apr|may|jun) matches the strings 23june2021 and 01july2021.

^

A carat matches a term that appears at the beginning of a string.

$

A dollar matches a term that appears at the end of a string.

Conclusion

Use the three functions when using regex in your SKILL code for faster searches. To know about the rules and these functions in detail, checkout the article How to use Regular Expressions in SKILL. This link can only be accessed if you have a valid login ID for the support site.

Do SUBSCRIBE to be updated about upcoming blogs. If you have any topic you want us to cover first or any feedback, you can write to us at pcbbloggers@cadence.com.

Tags:
  • regex |
  • 17.4 |
  • BoardSurfers |
  • PCB design |
  • Allegro Skill |
  • SKILL |
  • Allegro |