• 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. Replace last group digits with "*"

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 996
  • 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

Replace last group digits with "*"

Martinsh
Martinsh over 1 year ago

There are several group of digit number in a string. I'd like to replace all of the digits in the last group to "*" like following exsamples:

AAA123  --> AAA***

AAA123BBB234CCC  --> AAA123BBB***CCC

AAA123BBB234CCC34567DDD  --> AAA123BBB234CCC*****DDD

How to realize this with skill code? I tried rexReplace() function, but failed.

Regards,

Martin

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 1 year ago

    Martin,

    pat=pcreCompile("(\\d+)([^\\d]*)$")
    dig=pcreCompile("\\d")
    foreach(trial list("AAA123" "AAA123BBB234CCC" "AAA123BBB234CCC345DDD" "TEST123MORE5678OTHER")
      result=pcreReplace(pat trial "***\\2" 1)
      printf("%s -> %s\n" trial result)
      replacement=pcreReplace(dig pcreSubstitute(pat "\\1\\2") "*" 0)
      result=pcreReplace(pat trial replacement 1)
      printf("VARIABLE *: %s -> %s\n" trial result)
    )

    The second approach is if you want the number of * to be the same as the number of digits - ah, I see you edited the post to give that example (I wrote the code without having seen the edited post). rexReplace() is very basic, so using the pcre functions makes much more sense.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 1 year ago

    Martin,

    pat=pcreCompile("(\\d+)([^\\d]*)$")
    dig=pcreCompile("\\d")
    foreach(trial list("AAA123" "AAA123BBB234CCC" "AAA123BBB234CCC345DDD" "TEST123MORE5678OTHER")
      result=pcreReplace(pat trial "***\\2" 1)
      printf("%s -> %s\n" trial result)
      replacement=pcreReplace(dig pcreSubstitute(pat "\\1\\2") "*" 0)
      result=pcreReplace(pat trial replacement 1)
      printf("VARIABLE *: %s -> %s\n" trial result)
    )

    The second approach is if you want the number of * to be the same as the number of digits - ah, I see you edited the post to give that example (I wrote the code without having seen the edited post). rexReplace() is very basic, so using the pcre functions makes much more sense.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • Martinsh
    Martinsh over 1 year ago in reply to Andrew Beckett

    Andrew,

    It works well. Thanks!

    Martin

    • 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