     }.first
 
     if op != nil {
+#if swift(>=4.0)
+      expression = String(expression[expression.characters.index(after: expression.startIndex)..<expression.endIndex])
+#else
       expression = expression.substring(with: expression.characters.index(after: expression.startIndex)..<expression.endIndex)
+#endif
     }
 
     let regexes = expression.components(separatedBy: ",").map { variable -> String in

  /// Expand template as a URI Template using the given variables
  public func expand(_ variables: [String: Any]) -> String {
    return regex.substitute(template) { string in
      var expression = string.substring(with: string.characters.index(after: string.startIndex)..<string.characters.index(before: string.endIndex))
      let firstCharacter = expression.substring(to: expression.characters.index(after: expression.startIndex))

      var op = self.operators.filter {
        if let op = $0.op {

        var prefix:Int?

        if let range = variable.range(of: ":") {
#if swift(>=4.0)
          prefix = Int(String(variable[range.upperBound...]))
          variable = String(variable[..<range.lowerBound])
#else
          prefix = Int(variable.substring(from: range.upperBound))
          variable = variable.substring(to: range.lowerBound)
#endif
        }

        let explode = variable.hasSuffix("*")

        if explode {
#if swift(>=4.0)
          variable = String(variable[..<variable.characters.index(before: variable.endIndex)])
#else
          variable = variable.substring(to: variable.characters.index(before: variable.endIndex))
#endif
        }

        if let value: Any = variables[variable] {
