Regex for Contact has viewed at least one URL that matches regular expression

SOLVE
Highlighted
Occasional Contributor

Hi,

 

I'm trying to create a regex that matches:

 

https://www.youweagency.com/staffing

youweagency.com/staffing

youweagency.nl/staffing

youweagency.se/staffing

https://www.youweagency.com/e-commerce

youweagency.nl/e-commerce

 

where staffing or e-commerce can also be hosting or strategy-organization etc. (we have 8 of those in total),

 

but does not match:

 

https://www.youweagency.com/e-commerce/e-commerce-and-pim-one-integrated-suite

youweagency.nl/e-commerce/e-commerce-and-pim-one-integrated-suite

 

so anything after e-commerce (or any of the other 7) shouldn't match.

 

I've been trying this:

 

https\:\/\/(www\.|\.)youweagency\.(com|nl|se)\/(e\-commerce|staffing|hosting|strategy\-organization|experience\-design|data\-intelligence|digital\-marketing|content\-management)$

 

which I tested with https://www.regextester.com/ and worked fine.

 

I can't get it to work here in Hubspot though.

 

Could you please help?

 

Thanks in advance!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Solution
Esteemed Contributor | Platinum Partner

You need to make the https:// and www. strings optional

 

 

(?:https?\:\/\/)?(www\.)?youweagency\.(com|nl|se)\/(e\-commerce|staffing|hosting|strategy\-organization|experience\-design|data\-intelligence|digital\-marketing|content\-management)$

 

 

The ? makes anything preceeding it optional. Please note, I did not test this in hubspot.

 

Edit: if you want to account for query strings and tracking codes, then you could remove the $ at the end of the regex above and add the following code to the end: (?:\?.*)?



Will you please help the community and give me some street cred by marking my answer as a solution if helped you? I'm fixing to buy a minivan and my cool points are running low.

Curious cats can find me at Ascend Inbound Marketing

View solution in original post

7 Replies 7
Highlighted
Community Manager

Hi @helenechoo ,

 

Thanks for reaching out to the HubSpot Community. I'm not too familiar with this topic, but let's see if Community member can share some thoughs!

@tjoyce , is this topic something you can share advice? 

Highlighted
Top Advisor | Platinum Partner

I am going to tag @John - I have seen him write some beautiful regex's and hopefully he has an answer for you @helenechoo 

Highlighted
Esteemed Contributor | Platinum Partner

Thanks @tjoyce. @helenechoo, here are some questions for you to answer before any of us can help: Is this a text field, url field, or link field? Are you developing locally or in the hs IDE?



Will you please help the community and give me some street cred by marking my answer as a solution if helped you? I'm fixing to buy a minivan and my cool points are running low.

Curious cats can find me at Ascend Inbound Marketing

Highlighted
Occasional Contributor

Hi @John,

Thanks for reacting!

 

This is in the contact property Hubspot score:

Screenshot 2020-11-10 at 15.21.47.png

Sorry, not a developer so not sure whether this answers your question!

Let me know if you need any more information.

 

Best,

Helene

Reply
0 Upvotes
Highlighted
Solution
Esteemed Contributor | Platinum Partner

You need to make the https:// and www. strings optional

 

 

(?:https?\:\/\/)?(www\.)?youweagency\.(com|nl|se)\/(e\-commerce|staffing|hosting|strategy\-organization|experience\-design|data\-intelligence|digital\-marketing|content\-management)$

 

 

The ? makes anything preceeding it optional. Please note, I did not test this in hubspot.

 

Edit: if you want to account for query strings and tracking codes, then you could remove the $ at the end of the regex above and add the following code to the end: (?:\?.*)?



Will you please help the community and give me some street cred by marking my answer as a solution if helped you? I'm fixing to buy a minivan and my cool points are running low.

Curious cats can find me at Ascend Inbound Marketing

View solution in original post

Highlighted
Occasional Contributor

That worked, thanks!

Reply
0 Upvotes
Highlighted
Community Manager

Thank you @tjoyce for tagging in @John !