Wyrażenia regularne analytics – wyrażenie url zawierające url i wykluczające url

/wrap/boutiquehotels(?!boutiquehotelsi)(?!boutiquehotelsii)(?!boutiquehotelsiii)/

  • zawiera adres wrap/boutiquehotels ale już nie wrap/boutiquehotelsi oraz nie wrap/boutiquehotelsii oraz nie wrap/boutiquehotelsii

 

/wrap/boutiquehotelsi(?!boutiquehotels)(?!boutiquehotelsii)(?!boutiquehotelsiii)/

  • zawiera adres wrap/boutiquehotelsi ale już nie wrap/boutiquehotels oraz nie wrap/boutiquehotelsii oraz nie wrap/boutiquehotelsii

 

źródło kodu:

http://help.qualaroo.com/hc/en-us/articles/201541217-Excluding-URLs-Focusing-on-specific-URLs-Negative-and-Positive-Lookaheads

Negative Lookahead – How to exclude a portion of your site

One of the most useful implementations of this is the negative lookahead. It allows you to exclude whole sets of pages, files, subdomains, or any other part of the URL you don’t want to target. In regex terms, it looks for something that is NOT followed by something else. You specify what you DON’T want to include, and put it inside of these characters (?!StuffYouDontWant)

Example 1: Excluding a Section

I want to target my survey to all the pages on http://mysite.com/photos/, /cats/, and /documentation/ but not /users/ or any other single pages.

To use this example, you would add the following to your regex fields:

Subdomain: (www)?

TLD: mysite.com

Path: (?!users).*

This will target any page on my site in a subfolder, EXCEPT for all pages in the /users/ section, and anything not in a subfolder. For example,

And these pages do not show surveys:

Example 2: Excluding Groups of Pages

For the example used earlier in this section, say you want to target all the item pages in snacktastic.com/products/item-###, snacktastic.com/products/seasonal-### but excluding snacktastic.com/products/promo-###.

To use this example, you would add the following to your regex fields:

Subdomain: (www)?

TLD: snacktastic.com

Path: products\/(?!promo).*-\d+\/?

The survey will show up on:

But not

You could also use the | character to get the same results.

To use this example, you would add the following to your regex fields:

Subdomain: (www)?

TLD: snacktastic.com

Path: products\/(item|seasonal)-\d+\/?

There’s lots of ways to get to the same answer with regular expressions. You might find yourself using one set of tools more frequently than another, and that’s fine.

 


Reklamy

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Zdjęcie na Google+

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s