I'm trying determine the shipper from the tracking number using regex in a workflow rule formula. Similar too: https://stackoverflow.com/questions/619977/regular-expression-patterns-for-tracking-numbers

except when I escape the "/" for the editor the regex fails to match... so I'm kinda stuck.

Here is my original regex:

/\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d)\b/i

Here is my formula from the editor

IF(REGEX(Tracking_Number__c, '/\\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\\dT]\\d\\d\\d ?\\d\\d\\d\\d ?\\d\\d\\d)\\b/i'), "http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion<br>=5.0&sort_by=status&loc=en_US&InquiryNumber1="+ Tracking_Number__c, "")

2 Answers 2


Don't wrap your expressions in forward slashes (/), it's not Javascript! If you want to make your expression case-insensitive, begin it with the case-insensitive flag: (?i). Also, last I checked, Workflow Rules do not support REGEX, so you might have to move your logic to Process Builder.

  • Salesforce has documentation on regex which seems to elude that it can be used in formulas. developer.salesforce.com/forums/?id=906F00000008vYrIAI. I wrapped it as such as since I had read: "Regular expression syntax is based on Java Platform SE 6 syntax. However, backslash characters () must be changed to double backslashes (\) because backslash is an escape character in Salesforce.". However, you may be right. I have a case with Salesforce right now so I'll follow up with their input. Thanks
    – user39944
    Mar 15, 2017 at 16:06
  • You were right about the "/"'s. However the formula fields do support regex. Be weary of the support. As they had passed this case along to different reps one told me they wouldn't support it and tried to close my case. Another rep was very helpful.
    – user39944
    Mar 21, 2017 at 21:39
  • So basically my answer did resolve your issue? @user1040975
    – Adrian Larson
    Mar 21, 2017 at 21:44
  • In a manner of speaking, sure. I'll give it to ya. I'd just given you a bump, but I can't yet.
    – user39944
    Mar 21, 2017 at 21:47

It was a syntax issue:

\\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\\dT]\\d\\d\\d ?\\d\\d\\d\\d ?\\d\\d\\d)\\b

took out all the "/"'s and the case group. works.

You must log in to answer this question.