Tips, Tricks & Best Practices

helenechoo
Participant

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

SOLVE

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!

0 Upvotes
1 Accepted solution
John
Solution
Contributeur de premier rang | Partenaire solutions Platinum
Contributeur de premier rang | Partenaire solutions Platinum

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

SOLVE

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: (?:\?.*)?



I like kudos almost as much as cake – a close second.

View solution in original post

natsumimori
Community Manager
Community Manager

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

SOLVE

Thank you @tjoyce for tagging in @John !

John
Solution
Contributeur de premier rang | Partenaire solutions Platinum
Contributeur de premier rang | Partenaire solutions Platinum

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

SOLVE

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: (?:\?.*)?



I like kudos almost as much as cake – a close second.

helenechoo
Participant

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

SOLVE

That worked, thanks!

0 Upvotes
John
Contributeur de premier rang | Partenaire solutions Platinum
Contributeur de premier rang | Partenaire solutions Platinum

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

SOLVE

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?



I like kudos almost as much as cake – a close second.

helenechoo
Participant

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

SOLVE

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

0 Upvotes
tjoyce
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

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

SOLVE

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

natsumimori
Community Manager
Community Manager

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

SOLVE

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?