+;;;###autoload
+(defun ibuffer-mark-by-content-regexp (regexp &optional all-buffers)
+ "Mark all buffers whose content matches REGEXP.
+Optional arg ALL-BUFFERS, if non-nil, then search in all buffers.
+Otherwise buffers whose name matches an element of
+`ibuffer-never-search-content-name' or whose major mode is on
+`ibuffer-never-search-content-mode' are excluded."
+ (interactive (let ((reg (read-string "Mark by content (regexp): ")))
+ (list reg current-prefix-arg)))
+ (ibuffer-mark-on-buffer
+ #'(lambda (buf)
+ (let ((mode (with-current-buffer buf major-mode))
+ res)
+ (cond ((and (not all-buffers)
+ (or
+ (memq mode ibuffer-never-search-content-mode)
+ (cl-some (lambda (x) (string-match x (buffer-name buf)))
+ ibuffer-never-search-content-name)))
+ (setq res nil))
+ (t
+ (with-current-buffer buf
+ (save-mark-and-excursion
+ (goto-char (point-min))
+ (setq res (re-search-forward regexp nil t)))))) res))))
+