[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extract regexp
From: |
lawrence mitchell |
Subject: |
Re: extract regexp |
Date: |
Thu, 17 Apr 2003 18:11:26 +0100 |
User-agent: |
Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3.50 |
Bruce Ingalls wrote:
> I am trying to read a server name from Mozilla's prefs.js into a variable.
> The format of the string is
> user_pref("mail.server.server1.hostname", "pop.server.com");
> So the regular expression is something like
> user_pref\\("mail\\.server\\.server1\\.hostname", "([^"]+)"\\);
> How do I, for this case, read the file prefs.js, and load
> pop.server.com into
> a variable, "my-server"?
(let ((str "user_pref(\"mail.server.server1.hostname\", \"pop.server.com\");")
server)
(when (string-match
(concat "user_pref(\"mail\\.server\\.server1\\.hostname\", "
"\"\\([^\"]+\\)\");")
str)
(setq server (match-string 1 str))))
=> "pop.server.com"
to read in the file, do something like:
(with-temp-buffer
(insert-file-contents-literally "prefs.js")
(goto-char (point-min))
(condition-case err
(re-search-forward regexp)
(error (error "%s not found." regexp)))
(setq server (match-string 1)))
where regexp is as above.
--
lawrence mitchell <wence@gmx.li>
- extract regexp, Bruce Ingalls, 2003/04/17
- Re: extract regexp,
lawrence mitchell <=