From: Perry Smith <pedzsan@gmail.com>
To: gebser@mousecar.com
Cc: GNU Emacs List <help-gnu-emacs@gnu.org>
Subject: Re: string searching and saving results to a variable
Date: Tue, 15 Feb 2011 17:33:39 -0600 [thread overview]
Message-ID: <E179C733-E354-4BD3-95BE-94702DDD0B33@gmail.com> (raw)
In-Reply-To: <4D5B0901.5080100@mousecar.com>
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
next prev parent reply other threads:[~2011-02-15 23:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-15 23:15 string searching and saving results to a variable ken
2011-02-15 23:33 ` Perry Smith [this message]
2011-02-16 6:55 ` ken
2011-02-16 9:21 ` Oleksandr Gavenko
2011-02-16 16:58 ` ken
2011-02-19 11:16 ` Oleksandr Gavenko
2011-02-16 11:28 ` Le Wang
2011-02-17 10:51 ` ken
2011-02-17 13:30 ` Perry Smith
2011-02-18 17:33 ` ken
2011-02-18 18:16 ` Le Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E179C733-E354-4BD3-95BE-94702DDD0B33@gmail.com \
--to=pedzsan@gmail.com \
--cc=gebser@mousecar.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).