<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: -",
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NEURLFilterManager/setURLParsingRegularExpression(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "s:16NetworkExtension18NEURLFilterManagerC30setURLParsingRegularExpressionyySSSgKF"
  },
  "title" : "setURLParsingRegularExpression(_:)"
}
-->

# setURLParsingRegularExpression(_:)

Sets a regular expression for use in URL parsing.

```
func setURLParsingRegularExpression(_ pattern: String?) throws
```

## Discussion

Setting a regular expression allows you to perform custom URL parsing patterns beyond the standard parsing options.
The filter uses the regular expression to parse the URL before matching against the specified data set.

Calling this method validates the `pattern` you provide for the regular expression.
In your regular expression, use the standard name captured group syntax.
For example, `"https?://(?<host>[^/]+)"` captures the domain by using the group name `host`.
You can use whatever custom labels you want for group names, but they are limited to ASCII alphanumeric characters.

The result is a single string that uses the space character for a delimiter between each name-value pair, such as:

```
<group-1-name>=<group-1-value> <group-2-name>=<group-2-value> <group-3-name>=...
```

Providing a `pattern` without a named capture group throws an error.
If you provide a regular expression that uses other types of captured groups, only the named captured groups appear in the result.

Setting a regular expression causes the [`urlParsingConfiguration`](/documentation/NetworkExtension/NEURLFilterManager/urlParsingConfiguration) parameter to have no effect.
You can read the current value of the regular expression with the [`urlParsingRegularExpression`](/documentation/NetworkExtension/NEURLFilterManager/urlParsingRegularExpression) property.

URL parsing with a regular expression is case insensitive.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)