0

My requirement is NOT to have any combination of PO Box (P.O. Box, P. O. Box, etc) getting into any line of ShippingStreet of the Account record.

To achieve I have used the following Regex in Validation Rule which is working perfectly fine when ShippingStreet has any combination of PO Box (in any line). But if there is NO PO Box entered, then I'm seeing this error:

Validation Formula "PO_Box_check" Invalid (Regular expression runtime exceeded for: (?i)(?:(\r\n*.))\b(?:.p.?\so.?\s*|.post\s+office)\s+box.(\r\n*.)).*

REGEX( ShippingStreet , "(?i)(?:(\\r*\\n*.*)*)\\b(?:.*p\\.?\\s*o\\.?\\s*|.*post\\s+office)\\s*+box.*(\\r*\\n*.*)*")

Can anyone please help?

1
  • 1
    Suggest you use regex101.com to develop regular expressions. Provides help in creating them and allows easy testing.
    – Keith C
    Nov 10, 2016 at 21:48

1 Answer 1

0

I recommend you do a couple things:

  • Use the s flag to have . match newline characters. That will help you simplify your expressions.
  • Remove non-capturing groups. You're not using any of the groups, so you don't care if they are captured or not.

I was able to produce your runtime exceeded error with your initial validation formula, and the following worked just fine.

REGEX(ShippingStreet, "(?si).*\\b(p\\.?\\s*o\\.?\\s*|.*post\\s+office)\\s+box.*")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .