---
title: querystring.regfilter_except
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/query-string/querystring-regfilter-except
---

```
STRING querystring.regfilter_except(STRING url, REGEX pattern)
```

**Available in:** all subroutines

Returns the given URL but only keeps the parameters matching a regular
expression. Groups within the regular expression are treated as if they were 
written as non-capturing groups. For example:

```vcl
if (req.url.qs ~ "key-(?:[0-9]|\w)=([^&]*)-([^&]*)") { # captures to re.group.1 and re.group.2
  set req.url = querystring.regfilter_except(req.url, "key-([0-9]|\w)"); # does not capture
  set req.http.X-Key-1 = re.group.1;
  set req.http.X-Key-2 = re.group.2;
}
```

The `"key-([0-9]|\w)"` pattern shown here behaves as if it were written as a 
non-capturing group, `"key-(?:[0-9]|\w)"`, ensuring the contents of 
`re.group.1` and `re.group.2` are not affected by the call to 
`querystring.regfilter_except()`.

In this example, with a url of `/example?key-1=image-abc&something-else=xyz`
the captured groups `re.group.1` and `re.group.2` would be `image` and `abc`
respectively.

We're using `([^&]*)` rather than `(.*)` for the group capture from `req.url.qs`.
This is because we don't actually want to match every character, which would
include the `&something-else...` part. We only want to match up to the start
of the following key in the query string.
