• 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. Escaping backslash in pcreReplace patterns

Stats

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

Escaping backslash in pcreReplace patterns

Driss
Driss over 3 years ago

Hello Skill Community

I am getting into trouble when trying to escape backslash characters with PCRE expressions in skill.

My goal is to replace underscore characters in a given input string with   "\_" or sometimes with  "\\\_" 

So for instance:

inputSTR="TYP,Plan.3.Insertion_Loss_Fund_ATT0_TYP"
"TYP,Plan.3.Insertion_Loss_Fund_ATT0_TYP"

comPat1 = pcreCompile( "_" 0)
pcreobj@0x2e0be120

pcreReplace(comPat1 inputSTR "\\_" 0)
"TYP,Plan.3.Insertion_Loss_Fund_ATT0_TYP"

I put 2 blackslash characters in the last statement to escape its special meaning in Skill and would expect then this return: 

"TYP,Plan.3.Insertion\_Loss\_Fund\_ATT0\_TYP"

Similarly, if I would like to get 3 backslash in the end result, I would try this statement:

pcreReplace(comPat1 inputSTR "\\\\\\_" 0)

But skill returns:

"TYP,Plan.3.Insertion\\_Loss\\_Fund\\_ATT0\\_TYP"

as I would expect:

"TYP,Plan.3.Insertion\\\_Loss\\\_Fund\\\_ATT0\\\_TYP"

Can someone explain me where is my failure?

Thank you all in advance

Cedric

  • Cancel
  • mbracht
    mbracht over 3 years ago

    Hi Cedric,

    For each literal backslash in the result you need to specify 4(!) backslashes in your pcreReplace() call.
    So that creates one backslash:

    (pcreReplace (pcreCompile "_")  "A_B" "\\\\_" 0)

    ...and that one two:

    (pcreReplace (pcreCompile "_")  "A_B" "\\\\\\\\_" 0)

    Dont't let yourself get confused by the output in the CIW, literal backslashes as a return value are always indicated with another leading backslash:

    (pcreReplace (pcreCompile "_")  "A_B" "\\\\_" 0)
    "A\\_B"

    Just write the resulting string in a file and you will see that everything is as expected.

    Max

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Driss
    Driss over 3 years ago in reply to mbracht

    Indeed, thanks for your answer!

    • 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