String

public extension String
  • Returns the ranges of all matches of a regular expression which is provided as the pattern argument

    Throws

    An error indicating that the provided regular expression is invalid.

    Declaration

    Swift

    func matches(for pattern: String) throws -> [Range<String.Index>]

    Parameters

    pattern

    Regular expression for which matches should be searched

    Return Value

    Ranges of matches in the string for the given regular expression

  • Returns the ranges of all matches of the provided regular expression

    Declaration

    Swift

    func matches(for expression: NSRegularExpression) -> [Range<String.Index>]

    Parameters

    expression

    Regular expression for which matches should be searched

    Return Value

    Ranges of matches in the string for the given regular expression

  • Returns the ranges of all matches of a regular expression which is provided as the pattern argument

    Throws

    An error indicating that the provided regular expression is invalid.

    Declaration

    Swift

    func matches(for pattern: String, in range: Range<String.Index>) throws -> [Range<String.Index>]

    Parameters

    pattern

    Regular expression for which matches should be searched

    range

    Range of the string which should be checked

    Return Value

    Ranges of matches in the string for the given regular expression

  • Returns the ranges of all matches of the provided regular expression

    Declaration

    Swift

    func matches(for expression: NSRegularExpression, in range: Range<String.Index>) -> [Range<String.Index>]

    Parameters

    expression

    Regular expression for which matches should be searched

    range

    Range of the string which should be checked

    Return Value

    Ranges of matches in the string for the given regular expression

  • Returns a boolean value indicating that the string has a prefix which can be matched by the given regular expression

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func hasRegularPrefix(_ pattern: String) throws -> Bool

    Parameters

    pattern

    Regular expression

    Return Value

    True, if the regular expression matches a substring beginning at the start index of the string

  • Returns a boolean value indicating that the string has a prefix which can be matched by the given regular expression

    Declaration

    Swift

    func hasRegularPrefix(_ expression: NSRegularExpression) -> Bool

    Parameters

    pattern

    Regular expression

    Return Value

    True, if the regular expression matches a substring beginning at the start index of the string

  • Returns a boolean value indicating that the string has a prefix beginning at the given start index which can be matched by the given regular expression

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func hasRegularPrefix(_ pattern: String, from startIndex: String.Index) throws -> Bool

    Parameters

    pattern

    Regular expression

    startIndex

    Start index for the search

    Return Value

    True, if the regular expression matches a substring beginning at the start index of the string

  • Returns a boolean value indicating that the string has a prefix beginning at the given start index which can be matched by the given regular expression

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func hasRegularPrefix(_ expression: NSRegularExpression, from startIndex: String.Index) -> Bool

    Parameters

    pattern

    Regular expression

    startIndex

    Start index for the search

    Return Value

    True, if the regular expression matches a substring beginning at the start index of the string

  • Returns the range of a match for the given regular expression beginning at the start of the string

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularPrefix(_ pattern: String) throws -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    Return Value

    Range of the prefix matched by the regular expression or nil, if no match was found

  • Returns the range of a match for the given regular expression beginning at the start of the string

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularPrefix(_ expression: NSRegularExpression) -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    Return Value

    Range of the prefix matched by the regular expression or nil, if no match was found

  • Returns the range of a match for the given regular expression beginning at the start of the string

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularPrefix(_ pattern: String, from lowerBound: String.Index) throws -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    startIndex

    Start index for the search

    Return Value

    Range of the prefix matched by the regular expression or nil, if no match was found

  • Returns the range of a match for the given regular expression beginning at the start of the string

    Throws

    An error indicating that the provided regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularPrefix(_ expression: NSRegularExpression, from lowerBound: String.Index) -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    startIndex

    Start index for the search

    Return Value

    Range of the prefix matched by the regular expression or nil, if no match was found

  • Returns a boolean value indicating that the string ends with a substring matched by the given regular expression

    Throws

    An error indicating that the regular expression is invalid

    Declaration

    Swift

    func hasRegularSuffix(_ pattern: String) throws -> Bool

    Parameters

    pattern

    Regular expression

    Return Value

    True, if a match was found

  • Returns a boolean value indicating that the string ends with a substring matched by the given regular expression

    Throws

    An error indicating that the regular expression is invalid

    Declaration

    Swift

    func hasRegularSuffix(_ expression: NSRegularExpression) -> Bool

    Parameters

    pattern

    Regular expression

    Return Value

    True, if a match was found

  • Returns the range of a substring matched by the given regular expression ending at the end index of the string

    Throws

    An error indicating that the regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularSuffix(_ pattern: String) throws -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    Return Value

    Range of the match or nil, if no match was found

  • Returns the range of a substring matched by the given regular expression ending at the end index of the string

    Throws

    An error indicating that the regular expression is invalid

    Declaration

    Swift

    func rangeOfRegularSuffix(_ expression: NSRegularExpression) throws -> Range<String.Index>?

    Parameters

    pattern

    Regular expression

    Return Value

    Range of the match or nil, if no match was found

  • Returns a boolean value indicating that the string has a prefix described by the given terminal symbol.

    Declaration

    Swift

    func hasPrefix(_ prefix: Terminal) -> Bool

    Parameters

    prefix

    Sequence of terminal symbols

    Return Value

    True, if the string has a prefix described by the given non-terminal sequence

  • Returns a boolean value indicating that the string has a prefix from the given start index described by the given terminal symbol

    Declaration

    Swift

    func hasPrefix(_ prefix: Terminal, from startIndex: String.Index) -> Bool

    Parameters

    prefix

    Sequence of terminal symbols

    startIndex

    Index from which the search should start

    Return Value

    True, if the string has a prefix from the given start index described by the given non-terminal sequence

  • Returns the range of the prefix described by the given sequence of terminal symbols starting a the given start index

    Declaration

    Swift

    func rangeOfPrefix(_ prefix: Terminal, from startIndex: String.Index) -> Range<String.Index>?

    Return Value

    The range of the prefix or nil, if no matching prefix has been found

  • Performs replacements using the given replacement rules. The replacements are performed in order. Each replacement is a tuple of strings, where the first string is the pattern that is replaced and the second string is the string that is placed.

    Declaration

    Swift

    func replacingOccurrences<Replacements>(_ replacements: Replacements) -> String where Replacements : Sequence, Replacements.Element == (String, String)

    Parameters

    replacements

    Sequence of replacements to be performed

    Return Value

    String generated by performing the sequence of replacements provided

  • Escapes all special characters that need to be escaped to be escaped for the string to be printed as a string literal. This includes backslashes, line feeds, carriage returns and tab characters.

    Declaration

    Swift

    var literalEscaped: String { get }
  • Escapes all special characters that need to be escaped to be escaped for the string to be printed as a string literal enclosed by single quotes. This includes single quotes, backslashes, line feeds, carriage returns and tab characters.

    Declaration

    Swift

    var singleQuoteLiteralEscaped: String { get }
  • Escapes all special characters that need to be escaped to be escaped for the string to be printed as a string literal enclosed by double quotes. This includes double quotes, backslashes, line feeds, carriage returns and tab characters.

    Declaration

    Swift

    var doubleQuoteLiteralEscaped: String { get }