Quantcast
Channel: Cadence Custom IC Skill Forum
Viewing all articles
Browse latest Browse all 5201

Skill regex pcre {} quantifiers

$
0
0

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)


Viewing all articles
Browse latest Browse all 5201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>