• 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 PCB Editor
  3. Can I improve/simplify my regex code for finding certain...

Stats

  • Replies 4
  • Subscribers 159
  • Views 1126
  • Members are here 0
More Content

Can I improve/simplify my regex code for finding certain symbol names?

EvanShultz
EvanShultz over 15 years ago

I want to look at a comp's symbol for a keyword indicating the symbol is a leadless SMT package like BGA, QFN, etc. I'm using the code:

unique(mapcar(lambda((x) rexMatchp(x comp->package)) list(".BGA." ".DFN." ".QFN."))) == list(nil)

I check the package against a list of keywords using a regex, then I eliminate duplicate elements of the list to return a list of only nil if none of the keywords are found in the symbol (makes it easier to add additional keywords). I'm safe with this because our symbol library has naming rules which guarantee this will work.

 

This works, but seems overly complicated and requires verbose commenting. Are there better ways to do this? Here were my thoughts:

1. I tried to wrap mapcar(...) inside dptr() but it appears dtpr() doesn't interpret list(nil ... nil), or even list(nil), as an empty list.

2. The regex engine of Allegro SKILL doesn't seem to support advaned regex features I'm used to with other languages, such as pipe symbols. rexMatchp(".BGA|DFN|QFN." comp->package) always returns nil. Am I correct that advanced regex features, like pipes for alternation, aren't available in Allegro SKILL? It appears IC SKILL might from http://www.cadence.com/forums/p/14771/25538.aspx.

3. I couldn't come up with a solution that didn't use a regex, but it doesn't mean there isn't one.

  • Sign in to reply
  • Cancel
  • aCraig
    aCraig over 15 years ago

    Hi Evan

    Try this,

     apply('or mapcar(lambda((x) rexMatchp(x comp->package)) list(".BGA." ".DFN." ".QFN.")))

    This will return t if you get a match and nil if you don't.

    -Craig

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • aCraig
    aCraig over 15 years ago

    Hi Evan,

    It appears that pcreCompile, pcreExecute are supported in Allegro 16.2 in my case. pcreCompile supports "alternative" patterns like what's in your example. However there seems to be no documentation in the SPB docs. Maybe Andrew in the IC Forum can provide the pdf.

    -Craig

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • EvanShultz
    EvanShultz over 15 years ago

    Genius! Yes indeed, the pcre* functions are present and they work just as the rex* expressions, from what I can tell. But obviously much more powerful. Thanks Craig!

     

    To test each method, I wrapped them each in a for loop and cranked up the iterations until I reached an execution time which showed some difference between the methods. The method in my first post, as I suspected, isn't so good. Using apply() was 21% faster. Using pcreMatchp was another 19% faster, for a total speedup of 44%. Not the best way to gauge code efficiency, but it's quick and works on Windows.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • EvanShultz
    EvanShultz over 15 years ago

     FYI, 16.3 for Windows ships with an outdated version of sklangref.pdf. v07.02, the current release, has the pcre* functions and a few other new ones. Even zipped the PDF is more than 750kB, so I can't attach it here.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
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.

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

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