1

A team I work with is sending me leads with a single tracking code that represents several different facts about the leads, separated by ">" symbols. I've got a Process that is successfully splitting up the value and saving it to the appropriate fields, so when everything is formatted correctly, it works just fine.

The problem is that the systems/people who are sending me these values don't always get it right, and I can't guarantee the formatting (specifically, the inclusion of four ">" symbols) will always be correct. I'm trying to add an earlier step in the process to catch errors and save them to a different field to allow for manual correction/follow-up with the team that's made the error, and I think a REGEX expression is the right way to go, but it's not working as expected.

Here's the formula I'm using in my first decision point in the process; the business intent is to only trigger when the value has changed AND there is a value in the field AND where that value doesn't adhere to the proper format (XXX>XXX>XXX>XXX>XXX, where X could represent any number of characters that are a-z, A-Z, 0-9, &,-,., or /, but could be omitted):

AND(
  ISCHANGED([Lead].MarketingCode__c),
  NOT(ISBLANK([Lead].MarketingCode__c)),
  NOT(REGEX([Lead].MarketingCode__c, 
              "[\\w&-.\\/]*>[\\w&-.\\/]*>[\\w&-.\\/]*>

               [\\w&-.\\/]*>[\\w&-.\\/]"))
)

Unfortunately, this step is now always being hit, even when the format of MarketingCode__c is correct. I've done very little work with REGEX, so my first suspicion is that I've entered the expression incorrectly. Can anyone provide feedback on where I may have gone wrong? Thanks!

  • Is XXX>XXX>XXX>XXX>XXX the specific format that you need? – sfdcfox Nov 4 '16 at 23:28
  • No, I'm just intending the Xs to represent some set of characters. It could be nothing at all, or it could be a string of variable length with alphanumeric characters, or a handful of special characters (& - . /). Ultimately, what I want to verify is that there are four greater-than symbols. – Brian Pitts Nov 5 '16 at 6:30
3

First, &-. matches all characters between & and ., including *, (, ), ', etc. Move the dash to either the beginning, the end, or escape it.

This behavior happens any time you have a character set where the pattern .-. (where . means any character) occurs, because that forms a character range (e.g. a-z is a usual case, but it can actually be any two characters). This may cause some false positives/negatives.

Second, you can use the {} operator to limit the number of appearances of stuff, and () groups to perform repeats to shorten your code. Your long form simply makes it harder to read.

Third, instead of using *, I'd recommend using {,3} if you want to limit the code to three characters per set.

Fourth, be aware that \w also includes _, so you might want to use the longer form of \w minus the underscore.

This leads me to a final pattern of:

"([a-zA-Z0-9\\d&.\\/-]{,3}>){4}[a-zA-Z0-9&.\\/-]{,3}"

The rest of your formula looks okay, but you'll want to test this out to make sure. I wrote this as a validation rule in an object in my dev org, because I hate building processes just to test something like this, but it should work, at least in theory.

  • Thanks for the info! I'm not sure that it completely meets my needs (see response to your question above). I didn't intend the sets between greater-than symbols to be only three characters - it could be 0 characters, or it could be any length - but I can see how my description was confusing. I didn't know about the grouping operator, so I will test that over the weekend and see how it works. Thank you very much for your assistance! – Brian Pitts Nov 5 '16 at 6:34
  • I took your expression and, after reading up on {}, made a minor modification to change both instances of {,3} to {0,}. After testing as a validation rule in my personal developer org (first as a validation rule, then as a process), that appears to solve my problem. Thanks so much, both for the pattern provided and the thoughtful explanation! – Brian Pitts Nov 5 '16 at 10:26
  • @BrianPitts you can use * if the intent is zero or more matches. Either way, glad I could help. – sfdcfox Nov 5 '16 at 15:26

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.