• 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. Skill regex pcre {} quantifiers

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 16245
  • 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

Skill regex pcre {} quantifiers

FlxZer
FlxZer over 8 years ago

Hello folks,
 I'm trying to come up with a pcre pattern that would match at least 4 times (4 or more)  a given substring from parent string. Reading through Cadence documentation I found exactly what I need in sklangref.pdf on page 169. The example written there is this:

comPat3 = pcreCompile( "z{1,5}" ) => pcreobj@0x27d120
pcreExecute( comPat3 "zzzzz" ) => t

From my understanding, pcreExecute() should return => t  when "z"  is found at least 1 but not more than 5 times into given string. Is that correct ? I do have some perl background so I might be biased. So, If this assumption is correct the following piece of code should return nil

Theoretically:
comPat3 = pcreCompile( "z{1,5}" ) => pcreobj@0x27d120
pcreExecute( comPat3 "zzzzzzz" ) => nil
comPat3 = pcreCompile( "z{2,5}" ) => pcreobj@0x27d120
pcreExecute( comPat3 "z" ) => nil

However, when put to the test, the result is t


Practically:
comPat3 = pcreCompile( "z{1,5}" ) => pcreobj@0x27d120
pcreExecute( comPat3 "zzzzzzz" ) => t
comPat3 = pcreCompile( "z{2,5}" ) => pcreobj@0x27d120
pcreExecute( comPat3 "z" ) => t

Is there a piece of information I've missed on {} quantifiers or this is some sort of a bug?

And finally, this is how I end up asking this question. I am facing the following problem. I have a string with variables, which all have same prefix. I want to be sure that this string has at least 4 variables in it with "Don" prefix. Example:
str1 =  "  Don1 Don1_x Don1_y Don1_l Don1_w"
comPat1 = pcreCompile( "Don{4,}" )
pcreExecute(comPat1 str1) => (theoretically should return t, but it returns - nil)

str1 =  "  Don1 Don1_x Don1_y Don1_l"
comPat1 = pcreCompile( "Don{4,}" )
pcreExecute(comPat1 str1) => (theoretically should return t, but it returns - nil)

str1 =  "  Don1 Don1_x Don1_y"
comPat1 = pcreCompile( "Don{4,}" )
pcreExecute(comPat1 str1) => (theoretically should return nil. Practically it really does - nil)

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    The first example (with z's) are because the pattern is not anchored. What I see is if I do:

    comPat3=pcreCompile("z{2,5}")
    pcreExecute(comPat3 "z") ; nil
    pcreExecute(comPat3 "zz") ; t
    pcreExecute(comPat3 "zzzzz") ; t
    pcreExecute(comPat3 "zzzzzz") ; t

    The pattern is not anchored, so this means it is patching a sequence of 2 to 5 z's anywhere in the string. The last has 5 z's (which match) followed by some other characters, which happen to be a z. You could solve this by doing:

    comPat3=pcreCompile("^z{2,5}$")

    which means that the match can ONLY be zz, zzz, zzzz, or zzzzz. Anything else will return nil. Or you might need to make it more complex if you want to allow other characters:

    comPat3=pcreCompile("(^|[^z])z{2,5}([^z]|$)")

    This matches either the beginning, or a character other than z, followed by 2 to 5 z's, followed by any character other than z or the end of the string.

    For your second pattern, the repetition is on the "n" only. So you are asking for something with is Donnnn at least. That's not what you want.

    comPat1=pcreCompile("(Don\\S*\\s*){4,}")

    is probably what you want (I've not bothered with anchoring). What this is trying to match is Don followed by any number of non-space characters followed by any number of spaces, and then 4 or more repetitions of all of that (it's in parentheses to group the pattern).

    Note this is really not related to the implementation in SKILL (other than the \s and \S needing double escapes because of backslash having special meaning in SKILL strings). You could see the same syntax if you did "man perlre" - the syntax is using the Perl Compatible Regular Expression library.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    The first example (with z's) are because the pattern is not anchored. What I see is if I do:

    comPat3=pcreCompile("z{2,5}")
    pcreExecute(comPat3 "z") ; nil
    pcreExecute(comPat3 "zz") ; t
    pcreExecute(comPat3 "zzzzz") ; t
    pcreExecute(comPat3 "zzzzzz") ; t

    The pattern is not anchored, so this means it is patching a sequence of 2 to 5 z's anywhere in the string. The last has 5 z's (which match) followed by some other characters, which happen to be a z. You could solve this by doing:

    comPat3=pcreCompile("^z{2,5}$")

    which means that the match can ONLY be zz, zzz, zzzz, or zzzzz. Anything else will return nil. Or you might need to make it more complex if you want to allow other characters:

    comPat3=pcreCompile("(^|[^z])z{2,5}([^z]|$)")

    This matches either the beginning, or a character other than z, followed by 2 to 5 z's, followed by any character other than z or the end of the string.

    For your second pattern, the repetition is on the "n" only. So you are asking for something with is Donnnn at least. That's not what you want.

    comPat1=pcreCompile("(Don\\S*\\s*){4,}")

    is probably what you want (I've not bothered with anchoring). What this is trying to match is Don followed by any number of non-space characters followed by any number of spaces, and then 4 or more repetitions of all of that (it's in parentheses to group the pattern).

    Note this is really not related to the implementation in SKILL (other than the \s and \S needing double escapes because of backslash having special meaning in SKILL strings). You could see the same syntax if you did "man perlre" - the syntax is using the Perl Compatible Regular Expression library.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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