Vasily
Vasily

Reputation: 3790

Validate regex in Swift

Is it any way to validate regular expression in Swift that syntax of regex is correct?

E.g. user enters regex in TextField and I need to validate that one's syntax is correct.

Upvotes: 0

Views: 359

Answers (1)

Larme
Larme

Reputation: 26006

From the doc:

+ regularExpressionWithPattern:options:error:

For error parameter:

An out value that returns any error encountered during initialization. Returns an NSError object if the regular expression pattern is invalid; otherwise returns nil.

- initWithPattern:options:error:

For error parameter:

An out value that returns any error encountered during initialization. Returns an NSError object if the regular expression pattern is invalid; otherwise returns nil.

Upvotes: 1

Related Questions