In Visibility Rules, “Contains” means a regular expression, not a simple string match | Community
Skip to main content
SanfordWhiteman
Level 10
April 16, 2018

In Visibility Rules, “Contains” means a regular expression, not a simple string match

  • April 16, 2018
  • 8 replies
  • 5453 views

Little-publicized, to the point that even Support might not be in the loop: the Visibility Rule Contains operator does allow multiple values.

The Contains value is interpreted as a full-fledged regular expression, so use the pipe character | to separate sub-values:

ss

In fact, because of this unexpected/undocumented power, you must anchor an expression to avoid surprises:

^(TX|FL|PA)$ 

Otherwise, it's doing a partial match of the full value against each of your pipe-delimited alternatives. This might not be a problem on your forms right now, but if it becomes a problem, you wouldn't know about it immediately.

For example, if you were using uppercase state names, then

     Contains KANSAS|IDAHO

would match both ARKANSAS and KANSAS, and you should use

     Contains ^(KANSAS|IDAHO)$

instead.

You can also of course do more fancy matches with regexes if you want. And Not Contains is also a regex!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

8 replies

KellyJoHorton
Level 3
April 19, 2018

You just made my day. :^)

Kelly Jo HortonSenior Client PartnerEtumos503.928.1928khorton@etumos.com
Jace_Garside1
Level 2
April 16, 2021

I just tried implementing this to have rich text appear if a generic email is entered - sort of a quasi way to discourage personal email addresses without completely denying them. But it only recognizes the first value I have listed.  Any thoughts?

 

SanfordWhiteman
Level 10
April 17, 2021

That particular regex isn't what you want because it's checking if the value begins with the email domain. See my answer on your new thread: https://nation.marketo.com/t5/Product-Discussions/Visibility-Rules-with-Multiple-Values-within-Criteria/m-p/311899/highlight/true#M176118

BenCirillo
Level 2
June 3, 2021

Is there an expression that would work if I wanted to do the opposite: display values if Value A and Value B are true. 

 

I'm trying to do something like this (not this, but like this): 

Q: What topics are you generally interested in? 

(checkboxes)

  • Sports
  • Music
  • Theater

Then the followup question: 

What topics are you specifically interested in? (also checkboxes)

If you chose Sports only, you see: 

  • Football 
  • Baseball 
  • Soccer

If you chose Music only, you see: 

  • Rock
  • Opera
  • Jazz

If you chose Sports and Music, you see: 

  • Football
  • Baseball
  • Soccer
  • Rock
  • Opera
  • Jazz

Again, not a real example, but the concept is basically giving people a short list of broad categories to choose from, and then only as many specific topics as are relevant to them, to keep the form only as long as it needs to be. 

SanfordWhiteman
Level 10
June 3, 2021

I'm thinking yes, with a regex matching on the semicolon-delimited string you get from Checkboxes ("sports;theater"). But haven't tried this exact method.

Level 1
July 13, 2022

@sanfordwhiteman Is there a way to say search for two words that are not directly after each other but in the same string? I tried doing the above but that didn't work. 

 

If I had values like this:

Running;Long Jump;Triple Jump;

Running;Shotput;Triple Jump

Shotput;Long Jump

 

And I wanted to show a checkbox for if there selection contained Running and Jump, is that possible? I've tried using regex like this .*Running.*\.*Jump.*$ but Marketo doesn't like it.

SanfordWhiteman
Level 10
July 13, 2022

You definitely wouldn't want to escape the dot (\.) as that means a literal dot. But there aren't any dots in your sample strings.

 

You can use:

Running;.*Jump

but if this is a Checkboxes set or multi-Select it's clearer to include the explicit variations, since they're not infinite:

Running;.*(Triple Jump|Long Jump|High Jump)

 

Note this isn't really the same as checking against a list, as it relies on a specific order, "Running" always coming first. But if you ensure that order on the form, it's fine.

Level 1
July 13, 2022

Thanks so much!

 

I've ensured the order of the field so this works perfectly!