On Thu, 30 Apr 2009 11:57:06 -0700 (PDT) Xah Lee <xahlee@gmail.com> wrote:
XL> (let (p1 p2)
XL> (save-excursion
XL> (goto-char (point-min))
XL> (search-forward-regexp "^A.+$") ; begin pattern
XL> (setq p1 (point)) ; save cursor pos
XL> (search-forward-regexp "theq() :") ; ending pattern
XL> (backward-char 8)
XL> (setq p2 (point)) ; save cursor pos
XL> (setq mytext (buffer-substring p1 p2))
XL> )
XL> )
I don't think your first patten is exactly what the OP needed.
You can use (forward-line -1) to move the point back to the previous
line, and (beginning-of-line -1) to move to the beginning of the
previous line. Also, you don't need search-forward-regexp the second
time, just search-forward will work. Plus, of course, (backward-char 8)
is just asking for trouble.
Anyhow, regular expressions can handle multiple lines just fine:
A
theq() :
non
B
theq() :
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\(.*\\)\ntheq() :" nil t)
(message (match-string 1))))
will produce "A" and "B"
HTH
Ted