Contents

firstMatch(in:options:range:)

Returns the first match of the regular expression within the specified range of the string.

Declaration

func firstMatch(in string: String, options: NSRegularExpression.MatchingOptions = [], range: NSRange) -> NSTextCheckingResult?

Parameters

  • string:

    The string to search.

  • options:

    The matching options to use. See Matchingoptions for possible values.

  • range:

    The range of the string to search.

Return Value

An NSTextCheckingResult object. This result gives the overall matched range via its range property, and the range of each individual capture group via its range(at:) method. The range {NSNotFound, 0} is returned if one of the capture groups did not participate in this particular match.

Discussion

This is a convenience method that calls enumerateMatches(in:options:range:using:).

See Also

Searching Strings Using Regular Expressions