Instance Property


Returns the number of capture groups in the regular expression.


var numberOfCaptureGroups: Int { get }


A capture group consists of each possible match within a regular expression. Each capture group can then be used in a replacement template to insert that value into a replacement string.

This value puts a limit on the values of n for $n in templates, and it determines the number of ranges in the returned NSTextCheckingResult instances returned in the match... methods.

An exception will be generated if you attempt to access a result with an index value exceeding numberOfCaptureGroups-1.

See Also

Getting the Regular Expression and Options

var pattern: String

Returns the regular expression pattern.

var options: NSRegularExpression.Options

Returns the options used when the regular expression option was created.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software