Regex Data Studio exclude URL parameters

1.5k Views Asked by At

I have managed to use a Regex on Google Data Studio to create a 'last path' directory value which works great, using;

REGEXP_EXTRACT( Page , '.*/(.*)/' )

Is it possible to exclude URLs with parameters?

So for example the regex matches with;

/directory1/

/directory1/?var=1

/directory1/?var=2

So I wish to exclude any ?var= URLs but not limited to the var parameter value.

Any help is appreciated.

1

There are 1 best solutions below

0
On

To solve current issue use

REGEXP_EXTRACT( Page , '.*/(.*)/$' )

The anchor $ stops from matching anything with more text after /. If there is a query string, no match will occur.

Explanation

--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  /                        '/'
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  /                        '/'
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string