From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: lawrence mitchell Newsgroups: gmane.emacs.help Subject: Re: extract regexp Date: Thu, 17 Apr 2003 18:11:26 +0100 Organization: funfunfun Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <2vAna.20416$TR5.13296@twister.nyc.rr.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1050600247 5538 80.91.224.249 (17 Apr 2003 17:24:07 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 17 Apr 2003 17:24:07 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 17 19:24:00 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 196D1c-00011E-00 for ; Thu, 17 Apr 2003 19:18:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 196Cyn-00034I-01 for gnu-help-gnu-emacs@m.gmane.org; Thu, 17 Apr 2003 13:15:21 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!vegetable.demon.co.UK!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 37 Original-NNTP-Posting-Host: vegetable.demon.co.uk (80.177.16.3) Original-X-Trace: fu-berlin.de 1050599486 2573628 80.177.16.3 (16 [97657]) X-No-Yes: No Mail-Copies-To: nobody User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3.50 Cancel-Lock: sha1:IlwLQTDfQ7ffyTf2njV8NpVDnTY= Original-Xref: shelby.stanford.edu gnu.emacs.help:112058 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:8558 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:8558 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