[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string searching and saving results to a variable
From: |
Perry Smith |
Subject: |
Re: string searching and saving results to a variable |
Date: |
Tue, 15 Feb 2011 17:33:39 -0600 |
On Feb 15, 2011, at 5:15 PM, ken wrote:
> It's time again to write an elisp function!!
>
> One thing it needs to do a couple of times is save a string to a
> variable. The string to save will be an html header, like:
>
> <h3>Section 4</h3>
>
> but it could be multiple lines like this
>
> <h3 class="newest-chapter-section-type" align="center">On
> the origins of elisp confusion</h3>
>
> It could even be three or four lines long. Also, the line(s) could be
> indented and so have unwanted white space in the first several columns.
>
> Assuming the point is somewhere on that line or one of those lines, we do:
To be clean, first declare some variables
(defvar ....)
> (end-of-line) ; to preclude the point being at the far left.
> ; find the start of the string:
> (re-search-backward "<h1\\|<h2\\|<h3\\|<h4\\|<h5" nil t)
> ;;somehow mark this as the beginning of the string???
save the current point with:
(setq beg (point))
>
> ;find the endpoint of the string:
> (re-search-forward "</h1>\\|</h2>\\|</h3>\\|</h4>\\|</h5>" nil t)
>
> ;;save string to a variable to do other things with... how???
(setq dog (buffer-substring beg (point)))
dog now has the string