      (split s re 0))
     ([s re limit]
      (discard-trailing-if-needed limit
-       (if (= (str re) "/(?:)/")
+       (if (identical? "/(?:)/" (str re))
          (split-with-empty-regex s limit)
          (if (< limit 1)
            (vec (.split (str s) re))
            (loop [s s
                   limit limit
                   parts []]
-             (if (= limit 1)
+             (if (== 1 limit)
                (conj parts s)
-               (if-let [m (re-find re s)]
-                 (let [index (.indexOf s m)]
-                   (recur (.substring s (+ index (count m)))
-                          (dec limit)
-                          (conj parts (.substring s 0 index))))
-                 (conj parts s)))))))))
+               (let [m (re-find re s)]
+                 (if-not (nil? m)
+                   (let [index (.indexOf s m)]
+                     (recur (.substring s (+ index (count m)))
+                       (dec limit)
+                       (conj parts (.substring s 0 index))))
+                   (conj parts s))))))))))
 
 (defn split-lines
   "Splits s on \n or \r\n."

  (split s #"\n|\r\n"))

(defn trim
    "Removes whitespace from both ends of string."
    [s]
    (gstring/trim s))

(defn triml
    "Removes whitespace from the left side of string."
    [s]
    (gstring/trimLeft s))

(defn trimr
    "Removes whitespace from the right side of string."
    [s]
    (gstring/trimRight s))

(defn trim-newline
  "Removes all trailing newline \\n or return \\r characters from

    (if (zero? index)
      ""
      (let [ch (get s (dec index))]
        (if (or (identical? \newline ch)
                (identical? \return ch))
          (recur (dec index))
          (.substring s 0 index))))))

