Can Page Delivery use RegEx | Community
Skip to main content
Level 3
February 22, 2024
Question

Can Page Delivery use RegEx

  • February 22, 2024
  • 2 replies
  • 2212 views

How do I target all pages that match a pattern in Target's Page Delivery?
I'm needing to match 100's of pages that match like this for an A/B test:

example.com/path-name/
example.com/path-name/product-name

 

I tried example.com/* and example.com/*/*  but it didn't work.

 

Thanks!

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

2 replies

Rajneesh_Gautam_
Community Advisor
Community Advisor
February 22, 2024

Hi @jpfiber - I will suggest using profile scripts that support regular expressions and use current page URL value. 

Thanks

Rajneesh

JPFiberAuthor
Level 3
February 22, 2024

Hi @rajneesh_gautam_ - I'm not familiar with this.  Can you provide more information?

Thanks.

Community Advisor
June 3, 2024

Not sure if it's working, wrote this code and then created an audience for this.  It doesn't seem to be working.  Any further suggestions?

 

var urlRegex = new RegExp("^https://example\\.com(/pages)?/local/[a-zA-Z]+(/[a-zA-Z]+)?$"); var currentUrl = user.getLocal('pageURL'); // Assuming 'pageURL' is the variable that contains the full URL // If the URL matches the pattern, set a profile parameter if (urlRegex.test(currentUrl)) { user.setLocal('profile.regexMatch', 'true'); // Sets a profile parameter 'regexMatch' to 'true' } else { user.setLocal('profile.regexMatch', 'false'); // Sets the profile parameter to 'false' if there is no match }

 

I also have this as my audience setting:

 


You need to return true or false to the profile script in order for a value to be written to that key ...

 

LOCAL_PAGE_TARGETING 

 

... return true

 

The setLocal variables are used for temp storage of values to be assessed. 

Level 3
February 29, 2024

Hi @jpfiber 

 

In Adobe Target, to target multiple pages that match a specific pattern, you can use regular expressions in the URL targeting section. Regular expressions allow for more flexible and precise matching of URLs.

For your case, where you want to target pages with URLs like example.com/path-name/ and example.com/path-name/product-name, you can use a regular expression like:



 

^https?:\/\/example\.com\/path-name(?:\/.*)?$

 


Here's what this regular expression does:

^ asserts the start of the line.
https? matches both "http" and "https".
:\/\/example\.com\/path-name matches the literal string "://example.com/path-name".
(?:\/.*)? is a non-capturing group that matches an optional forward slash followed by any characters.
$ asserts the end of the line.
This regular expression matches URLs that start with https://example.com/path-name/ and may optionally have additional characters after /path-name/.

To set up this targeting in Adobe Target:

Navigate to your A/B test in Adobe Target.
Go to the targeting section.
Choose URL as the targeting dimension.
Select "Matches Regular Expression" as the operator.
Enter the regular expression: ^https?:\/\/example\.com\/path-name(?:\/.*)?$
This setup will target all URLs that match the specified pattern. Make sure to test your regular expression thoroughly to ensure it's capturing the desired URLs correctly.