• 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. How to backreference named captures in pcreSubstitute

Stats

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

How to backreference named captures in pcreSubstitute

tweeksii
tweeksii over 7 years ago

I am able to use numbered backreferences within pcreSubstitute:

> string = "cdsDefTechLib from file internal_implicit"
"cdsDefTechLib from file internal_implicit"
> pcreExecute(pcreCompile("(\\w+) from file (\\w+)") string)
t
> pcreSubstitute("Found \\1 and \\2.")
"Found cdsDefTechLib and internal_implicit."
>

But when I try to use named backreferences, pcreSubstitute doesn't seem to understand them!

> pcreExecute(pcreCompile("(?P<f>\\w+) from file (?P<b>\\w+)")
string)
t
> pcreSubstitute("Found \\k<FOO> and \\k<BAR>")

"Found k<FOO> and k<BAR>"
> pcreSubstitute("Found \\k'FOO' and \\k'BAR'")
"Found k'FOO' and k'BAR'"
> pcreSubstitute("Found \\k{FOO} and \\k{BAR}")
"Found k{FOO} and k{BAR}"
> pcreSubstitute("Found ?P<FOO> and ?P<BAR>")
"Found ?P<FOO> and ?P<BAR>"
> pcreSubstitute("Found \\?P<FOO> and \\?P<BAR>")
"Found ?P<FOO> and ?P<BAR>"
> pcreSubstitute("Found \\(?P=FOO\\)")
"Found (?P=FOO)"
> pcreSubstitute("Found (?P=FOO)")
"Found (?P=FOO)"
> pcreSubstitute("Found (?p=FOO)")
"Found (?p=FOO)"


So, does anybody know how to refer to named backreferences in pcreSubstitute (and pcreReplace)?

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    Tom,

    I think it's probably that we're using too old a version of PCRE (from pcre.org) - it was first added about 12 years ago and it may not have been updated since. I suspect only limited support for named back references was available then (I think it was modelled after Python's syntax then). I can't get it to work either.

    You probably should contact customer support so that we can get PCRE updated (if this is indeed the problem) to use a newer version of the libraries.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tweeksii
    tweeksii over 6 years ago in reply to Andrew Beckett

    Hi Andrew,

    Sorry for the late reply--there have been some rather distracting events at my employer recently, but I wanted to be sure to thank you for your detailed answer. 

    After discussing the matter with my colleagues, we decided to hold off on opening a customer support case until we really need to use this feature, as thus far we have been content to use the numbered backreferences (this issue only came up because a contractor asked about it out of curiosity).  It's good to know that the documentation on pcre.org might describe features that are not available (yet) in the version built into Virtuoso!  I wonder if there's a way to directly determine which version is actually in Virtuoso today....

    • 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