---
title: "escapedTemplate(for:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsregularexpression/escapedtemplate(for:)"
---

# escapedTemplate(for:)

Returns a template string by adding backslash escapes as necessary to protect any characters that would match as pattern metacharacters

## Declaration

```swift
class func escapedTemplate(for string: String) -> String
```

## Parameters

- `string`: The template string

## Return Value

Return Value The escaped template string.

## Discussion

Discussion Returns a string by adding backslash escapes as necessary to the given string, to escape any characters that would otherwise be treated as pattern metacharacters. You typically use this method to match on a particular string within a larger pattern. For example, the string "(N/A)" contains the pattern metacharacters (, /, and ). The result of adding backslash escapes to this string is "\\(N\\/A\\)". See Flag Options for the format of the resulting template string.

## See Also

### Escaping Characters in a String

- [escapedPattern(for:)](foundation/nsregularexpression/escapedpattern(for:).md)
