method re_search forward ?(start=buffer#start_iter) ?(stop=buffer#end_iter) re =
      try
        (* warning: if we search backward, we must start on charcrater back that the
           one indicated, because Str starts with the given start position, not before the
           start position; that is different from the [GSourceView.iter_backward_search] function
           and the way gtk handles this in general, so we make this hack to act the same way.
           *)

        let (text) = buffer#get_text ~start ~stop () in
        let f = if forward then self#re_search_forward else self#re_search_backward in
        let offset = start#offset in
(*
        prerr_endline (Printf.sprintf "offset=%d" offset);
*)

        let (char_start, char_end) = self#pcre_offset_tuple_to_char_indices text (f re text) in
        let (char_start, char_end) = (char_start + offset, char_end + offset) in
        (*        prerr_endline (Printf.sprintf "found: start=%d end=%d" char_start char_end);*)
        let start = buffer#get_iter (`OFFSET char_start) in
        let stop = buffer#get_iter (`OFFSET char_end) in
        Some (start, stop)
      with
        Not_found ->
          None