• 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. search for pattern in a string

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 144
  • Views 12028
  • 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

search for pattern in a string

greywanderer
greywanderer over 3 years ago

Hi,

How do you search for a pattern in a string and return the pattern found?

For eg. say the string "/a/b/c/Interactive.123/d/e/"

And regex pattern is "Interactive.[0-9]+".

Is there a skill function that returns "Interactive.123" when function("/a/b/c/Interactive.123/d/e/" "Interactive.[0-9]+")?

Thanks!

  • Cancel
  • skillUser
    skillUser over 3 years ago

    Hi,

    str = "/a/b/c/Interactive.123/d/e/"
    => "/a/b/c/Interactive.123/d/e/"
    pat = pcreCompile("(Interactive\\.[0-9]+)")
    => pcreobj@0x2aa37260
    pcreExecute(pat str)
    => t
    pcreSubstitute(pat "\\1")
    => "Interactive.123"

    The "." in the pattern needed to be escaped otherwise it means 'any single character' rather than a literal dot. The whole captured pattern is surrounded with parentheses, and since this is the first captured pattern it is referred to as \\1 in the replacement, this is what the pcreSubstitute function is returning to us, the first captured (sub)-pattern.

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • henker
    henker over 3 years ago in reply to skillUser

    You can get the actual match also with \\0. This does not require an explicit capture group around the whole pattern, e.g. pcreCompile("Interactive\\.[0-9]+") without the capture parentesis in the regex and pcreSubstitute(pat "\\0") will do the same and may be a bit more intuitive.

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to henker

    In addition to \\0 you can also use & - so:

    pcreSubstitute(pat "&") 

    will do the same thing. Of course, your pattern could also be "Interactive\\.\\d+" (\d is perl regular expression for a digit).

    Andrew

    • Cancel
    • Vote Up +1 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