• 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. Custom IC SKILL
  3. Replacing characters in a string

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 17629
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Replacing characters in a string

Michael L
Michael L over 5 years ago

I have a layout with instance names that use the underscore as the array delimiters.  For example, instance names such as IDQ_7_.  I want to use SKILL to change the delimiters from underscore to parentheses, changing my example to IDQ(7).  In this specific situation, the following section of code works just fine:

while( rexMatchp( "_[0-9]_" Name )

     rexCompile( "_" )

     Name = rexReplace( Name "(" 1 )

     rexCompile( "_" )

     Name = rexReplace( Name ")" 1 )

)

item~>baseName = Name

My problem is that I also have instance names similar to xofiller_fill15m2_1_.  My above code example will result in the variable Name having a value of xofiller(fill15m2)1_.  This is obviously incorrect, what I want is xofiller_fill15m2(1) instead.  

First, how do I modify my code to change the underscores that surround only a number, while leaving all other underscores alone?

Second, I would just like verification that my "while rexMatchp" line would work on all numbers, not just those with a single digit.  I am still working on the underscore issue, haven't even tried to see if it would catch "_32_" yet.

. 

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago

    I would use the more powerful pcre functions (unless using IC5141, which is so old that these had not yet been introduced - they were added for IC610, I believe):

    underNumsUnder=pcreCompile("_([0-9]+)_")
    name="xofiller_fill15m2_1_"
    pcreReplace(underNumsUnder name "(\\1)" 1)
    "xofiller_fill15m2(1)"

    You can do it with the older rex interface, although the brackets in the pattern have to be escaped:

    rexCompile("_\\([0-9]+\\)_")
    rexReplace(name "(\\1)" 1)

    The idea with both approaches is that you are capturing the entire pattern - an underscore, followed by one or more numbers, followed by an underscore, and surrounding the piece you want to keep with parentheses. You can then refer to these remembered pieces by using \1, \2 etc, but because backslash also escapes special characters in strings, you need to have a double backslash.

    So if you did:

    name="xofiller_fill15m2_32_"

    that would also work (with both the pcre and rex approaches).

    Hope that helps!

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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