1

Can someone help me understand the following statement from the Apex Developer Guide? I'm trying to understand regular expressions, but this statement has me a bit confused, and I can't figure out how/when a developer could hit this limit:

Salesforce limits the number of times an input sequence for a regular expression can be accessed to 1,000,000 times. If you reach that limit, you receive a runtime error.

How/when is a regular expression accessed? Can you give a simple use case of when something like this could happen?

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_using.htm

The reason I'm asking, is that we are planning to put a batch process in place to evaluate all phone fields on our Accounts and Contacts, and if the country code is US or Canada, we'll add (if it's not already there) a '+1' to the phone number so that the number can be auto-dialed from any country of origin. We have 5 phone fields on Contact alone, and we're concerned about limits.

2

I belive what it's referring to is the number of times a string is accessed while processing a regex against it.

Regular expressions can do all sorts of weird and wonderful things with back-tracking etc. that means they have to run backwards and forwards over the String many times to decide if it's a match. I think this limit is referring to the number of times the variable needs to be read during a regex evaluation, and I can only see this limit being hit with a complicated expression on a long string (think HTML page body or something).

For your use case you'll have no need for concern regarding this limit.

  • You are a gentleman and a scholar Mr Lacey. Thanks as well to Tammer, the article helped as well. – HomerJ Jan 13 '16 at 23:23
1

It has to do with the complexity of the Matcher. In practical terms your Matcher String can't be over 1M or you will hit that limit.

https://help.salesforce.com/apex/HTViewSolution?id=000005024&language=en_US

Your use case should be OK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.