---
title: "regularExpressionWithPattern:options:error:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsregularexpression/regularexpressionwithpattern:options:error:"
---

# regularExpressionWithPattern:options:error:

Creates an NSRegularExpression instance with the specified regular expression pattern and options.

## Declaration

```occ
+ (NSRegularExpression *) regularExpressionWithPattern:(NSString *) pattern options:(NSRegularExpressionOptions) options error:(NSError **) error;
```

## Parameters

- `pattern`: The regular expression pattern to compile.
- `options`: The matching options. See doc://com.apple.foundation/documentation/Foundation/NSRegularExpression/Options-swift.struct for possible values. The values can be combined using the C-bitwise OR operator.
- `error`: An out value that returns any error encountered during initialization. Returns an NSError object if the regular expression pattern is invalid; otherwise returns nil.

## Return Value

Return Value An instance of NSRegularExpression for the specified regular expression and options.

## See Also

### Creating Regular Expressions

- [init(pattern:options:)](foundation/nsregularexpression/init(pattern:options:).md)
