String

public extension String

Regular Expression Patterns

  • An NSRange that represents the full range of the string.

    Declaration

    Swift

    var fullNSRange: NSRange { get }
  • Returns a substring with the given NSRange, or nil if the range can’t be converted.

    Declaration

    Swift

    func substring(with nsRange: NSRange) -> String?
  • Returns a range equivalent to the given NSRange, or nil if the range can’t be converted.

    Declaration

    Swift

    func range(from nsRange: NSRange) -> Range<Index>?

Regex Related

  • Replacing regular expression matches with template string. Could use self.replacingOccurrences(of: pattern, with: template, options: .regularExpression)

    Declaration

    Swift

    func replacingMatches(
      of pattern: String,
      options: NSRegularExpression.Options = [],
      matchingOptions: NSRegularExpression.MatchingOptions = [],
      with template: String
    ) throws -> String
  • Returns matched strings of a regular expression pattern.

    Declaration

    Swift

    func matchedStrings(
      of pattern: String,
      options: NSRegularExpression.Options = [],
      matchingOptions: NSRegularExpression.MatchingOptions = []
    ) -> [String]
  • Undocumented

    Declaration

    Swift

    func firstMatchedString(of pattern: String,
                            options: NSRegularExpression.Options = [],
                            matchingOptions: NSRegularExpression.MatchingOptions = []) -> String?
  • Returns captured groups of a regular expression pattern for provided match index.

    Declaration

    Swift

    func capturedGroups(
      of pattern: String,
      options: NSRegularExpression.Options = [],
      matchingOptions: NSRegularExpression.MatchingOptions = [],
      matchIndex: Int = 0
    ) -> [String]