Using regex for url in triggers | Community
Skip to main content

Using regex for url in triggers

  • June 3, 2016
  • 5 replies
  • 0 views

I wanted a trigger to work when the users were on two areas of our website. I tried to use a regex to do this. I tried a couple of versions. First a simple one (that works in Python):
portal.somniumtech.com/products|www.somniumtech.com

Then, because of the slightly cryptic comment about only doing a "full" match, I tried:
^https?://(portal.somniumtech.com/products|www.somniumtech.com).*$

In both cases, the trigger never fired.

I worked around this by using the (undocumented) developer mode and using nested conditionals:

    "condition": [
        "and",
        [
            "or",
            [
                "icontains",
                "@visitor_page_url",
                "portal.somniumtech.com/products"
            ],
            [
                "icontains",
                "@visitor_page_url",
                "www.somniumtech.com"
            ]
        ],

That seems to work. But means I can't switch back to the Visual view.

Any idea why the regex doesn't work?

This topic has been closed for replies.

5 replies

  • Author
  • June 6, 2016

After a lot of fiddling about trying to diagnose another problem, I found the following regex does work:

.*www.somniumtech.com.*|.*portal.somniumtech.com/products.*

I assume the regex engine is very limited in what it accepts. Apparently not Python regexes as implied by the documentation.


  • June 7, 2016

Hi Jamie,

The 2 regex examples you gave above should work. In order to ensure the integrity of our triggers, we actually do not fire events if a page refresh on the same page URL happens. This makes sures that triggers only fires on a true page load event.

Perhaps you can try these regexes again, and open your pages in incognito to see if the trigger really fires


  • Author
  • June 7, 2016

Hi Yunen,

Thanks for the reply. I think you are right: I was probably using page refreshes to test the trigger. This would explain why I had such a hard time getting it to fire. I think I spent a lot of time trying to debug problems that weren't there!

Is this fact documented anywhere? How about a blog post with tips on how to test triggers...?


  • June 8, 2016

Hi Jamie,

Good idea on an article on how to test triggers. Let me speak to my content team and see if they can whip something up!


  • Author
  • June 8, 2016