+(defvar sort-regexp-fields-regexp)
+(defvar sort-regexp-record-end)
+
+;; Move to the beginning of the next match for record-regexp,
+;; and set sort-regexp-record-end to the end of that match.
+;; If the next match is empty and does not advance point,
+;; skip one character and try again.
+(defun sort-regexp-fields-next-record ()
+ (let ((oldpos (point)))
+ (and (re-search-forward sort-regexp-fields-regexp nil 'move)
+ (setq sort-regexp-record-end (match-end 0))
+ (if (= sort-regexp-record-end oldpos)
+ (progn
+ (forward-char 1)
+ (re-search-forward sort-regexp-fields-regexp nil 'move)
+ (setq sort-regexp-record-end (match-end 0)))
+ t)
+ (goto-char (match-beginning 0)))))
+