How exactly does the OperationLimit Property on the Regex-Matcher work, and how do I get it to work?
Hi there,
I want to use regex in my code, and I saw that the %Regex.Matcher class contains a property "OperationLimit" that you can also set to a number of steps that the regex engine should take maximum in analysing a given string. So far so good.
I tried to set the property with the function OperationLimitSet() to a silly value like 3. In 3 steps only very few regex should be executed, right? But what I found is that my regex always comes up with a solution. Here is what I did:
First I initialised my %Regex.Matcher.
set m = ##class(%Regex.Matcher).%New("(.+)\@(.+)\.(.+)")
do m.OperationLimitSet(3)
do m.TextSet("thisismytest@email.com")
Then I ran the regex and found my 3 groups.
zw m.Locate()
1zw m.Group(1)
"thisismytest"zw m.Group(2)
"email"zw m.Group(3)
"com"
Now maybe I have completely misunderstood the OperationLimit property, or my implementation of this simple regex matcher is faulty, but the documentation clearly states: "Setting OperationLimit to a positive integer will cause a match operation to signal a TimeOut error after the specified number of clusters of steps by the match engine". As I am using the Locate() function and not the Match() function, I wondered if the documentation specifically talks about the Match() function. But both the Locate() and Match() function execute without any problem.
set m = ##class(%Regex.Matcher).%New("(.+)\@(.+)\.(.+)")
do m.OperationLimitSet(3)
do m.TextSet("thisismytest@email.com")
zw m.Match()
1I would appreciate any input as to why my regex is still running perfectly and what I can do to prevent this, as I would obviously like to set a realistic OperationLimit of 4000 or something in that range in the future.
Thanks for your help!
Comments
Well, documentation says:
Setting OperationLimit to a positive integer will cause a match operation to signal a TimeOut error after the specified number of clusters of steps by the match engine.
Maybe the key question here is...what is a cluster of steps?