From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Len Blanks Newsgroups: gmane.emacs.help Subject: Troubles in Regular Expression Paradise Date: Tue, 13 May 2014 21:18:58 -0500 Organization: Socialist Workers Computational Vision and Robotics Collective Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1400034924 26763 80.91.229.3 (14 May 2014 02:35:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 May 2014 02:35:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 14 04:35:18 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WkP2J-0006Ps-FV for geh-help-gnu-emacs@m.gmane.org; Wed, 14 May 2014 04:35:15 +0200 Original-Received: from localhost ([::1]:48946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkP2I-0006kK-Jb for geh-help-gnu-emacs@m.gmane.org; Tue, 13 May 2014 22:35:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkOt4-0005bz-1v for help-gnu-emacs@gnu.org; Tue, 13 May 2014 22:25:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkOsy-0000eE-3K for help-gnu-emacs@gnu.org; Tue, 13 May 2014 22:25:42 -0400 Original-Received: from haruspex.net ([72.52.120.134]:51181) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1WkOsx-0000dJ-EW for help-gnu-emacs@gnu.org; Tue, 13 May 2014 22:25:35 -0400 Original-Received: from localhost ([70.171.94.129]) by haruspex.net for ; Tue, 13 May 2014 19:19:02 -0700 Mail-Copies-To: never X-GPG-Key-ID: C7189399 X-GPG-Fingerprint: 1938 0CB6 C718 9399 X-url: http://www.haruspex.net/ X-Attribution: Len X-Unexpected: The Spanish Inquisition X-Mayan-date: Long count = 13.0.1.7.8; tzolkin = 5 Lamat; haab = 1 Zip X-Now-Playing: \2's \1 from the CD \3 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEU4UGpBMilwYVcRIhyt gGbAxso98L7wAAACeElEQVQ4jWWTS5YbIQxFBbbnCCpzkKm5sXoBbQILsEPtfyt5VDk56Q4e uI4uTx8kkc+tb/+ear1PfiP+DsQajn78D6IAXF4TfLFv9ZM59scEX8mrEsfGACLfgE3x8UEs BxhtyOgQv6KXeIpUvMgRvfK63yDypIHKUusBEv+AeXvNdFXJ+0c9EssPKMZ4SWBSRzdf31Ea /juAZYAzFRHjZpSRa0p+jGpNcq4jq8jG9q3VypLDOprj5M6NkJsBGK0l5Bc+tsGc/PmTuMUk 1EedgLX0CmBtgKs0QRPE5qCahU/FG0WByTC1mlp6AxfUaSH1EQD3chIP0MSpMgoECxzzY5ku uYQqjBMmMAF5ytISCxSSQgiHwqBSRAaAq4L+cbjN4tkghviUU0mq9zo9OSYANozSsoQ7QJEZ wK2YkoIbOZqlOosQOkFBuyi3atD3bPhGugNFt3slOBmGaDVowQSJAztqg4xL65P5grLoBGD2 kNtGSFM25h94iB0gFz9bDVfRIsyC5HdghfbJIIIzaSfPShOEy97kHCnSfEODh44TlI4JazlZ ImscqH0D3UaEdwWgxACFw+eueD0cjOoRApU69DTsinu7FtgKhppcmoWx1r30oAGPVAI5wqOV xE8dZKFIQKzoebiLXjGjv3SD6+t9a8HGcFO63sUP5P4EMBPgdAwZKj928KntL5hDT39W86Ur Yuygbx1gumm4MXShs/68j7eEdl2HLCx0CU+AhtPbBPNj264rfQDsdhyMcxu40AHcck33wywZ TZwf0IU1LdHcGhYsV3vGnLdtemoxYw/IYt8kElso+qGuOSqMO4okBMt6gCZEYiyAxe83uezJ 8or1mNUAAAAASUVORK5CYII= iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEU4UGpBMilwYVcRIhyt gGbAxso98L7wAAACeElEQVQ4jWWTS5YbIQxFBbbnCCpzkKm5sXoBbQILsEPtfyt5VDk56Q4e uI4uTx8kkc+tb/+ear1PfiP+DsQajn78D6IAXF4TfLFv9ZM59scEX8mrEsfGACLfgE3x8UEs BxhtyOgQv6KXeIpUvMgRvfK63yDypIHKUusBEv+AeXvNdFXJ+0c9EssPKMZ4SWBSRzdf31Ea /juAZYAzFRHjZpSRa0p+jGpNcq4jq8jG9q3VypLDOprj5M6NkJsBGK0l5Bc+tsGc/PmTuMUk 1EedgLX0CmBtgKs0QRPE5qCahU/FG0WByTC1mlp6AxfUaSH1EQD3chIP0MSpMgoECxzzY5ku uYQqjBMmMAF5ytISCxSSQgiHwqBSRAaAq4L+cbjN4tkghviUU0mq9zo9OSYANozSsoQ7QJEZ wK2YkoIbOZqlOosQOkFBuyi3atD3bPhGugNFt3slOBmGaDVowQSJAztqg4xL65P5grLoBGD2 kNtGSFM25h94iB0gFz9bDVfRIsyC5HdghfbJIIIzaSfPShOEy97kHCnSfEODh44TlI4JazlZ ImscqH0D3UaEdwWgxACFw+eueD0cjOoRApU69DTsinu7FtgKhppcmoWx1r30oAGPVAI5wqOV xE8dZKFIQKzoebiLXjGjv3SD6+t9a8HGcFO63sUP5P4EMBPgdAwZKj928KntL5hDT39W86Ur Yuygbx1gumm4MXShs/68j7eEdl2HLCx0CU+AhtPbBPNj264rfQDsdhyMcxu40AHcck33wywZ TZwf0IU1LdHcGhYsV3vGnLdtemoxYw/IYt8kElso+qGuOSqMO4okBMt6gCZEYiyAxe83uezJ 8or1mNUAAAAASUVORK5CYII= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (darwin) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 72.52.120.134 X-Mailman-Approved-At: Tue, 13 May 2014 22:35:03 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97636 Archived-At: I'm trying to parse an xml file containing information for a song "currently playing" on my iTunes - specifically the artist, name of the tune and the CD in appears on. Here's an example of the file: <![CDATA[Hold On]]> MPEG audio file 1 12 2012 249 1 1 No http://www.amazon.com/Boys-Girls-Alabama-Shakes/dp/B0074MZSWW%3FSubscriptionId%3D03AKJ1J6S0FY8K0WRER2%26tag%3Dnowplaplu-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0074MZSWW http://ecx.images-amazon.com/images/I/61P1-X1QkoL._SL75_.jpg http://ecx.images-amazon.com/images/I/61P1-X1QkoL._SL160_.jpg http://ecx.images-amazon.com/images/I/61P1-X1QkoL.jpg c53ba0b14763278952c3fb1f8ea1da1f and here is a function I had hoped would strip the relevant fields and return a string in the form: "_artist_'s _title_ from the CD _album_" to be inserted in a X-NOW-PLAYING: header in emails and usenet posts: (defun now-playing (xml-file) ;; (interactive "FFile: ") (with-temp-buffer (insert-file-contents xml-file) (goto-char 1) (when (re-search-forward (concat "<!\\[CDATA\\[\\([^\\]+\\)\\]>" "[\0-\377[:nonascii:]]*" "" "[\0-\377[:nonascii:]]*" "") nil t) (concat "\\2" (if (string= (downcase (substring "\\2" -2 -1)) "s") "'" "'s") " \\1 from the CD \\3")))) (message (now-playing "/tmp/now_playing.xml")) ;; test now-playing The regular expression was built and tested using re-build and it works well in matching including the groupings \\( ... \\), which re-build colours quite nicely. But I seem to have done something really foolish since referencing \\1, \\2 and \\3 fail, so they don't seem to be properly set by the groupings in the re. The function returns "\2's \1 from the CD \3". I'm sure the problem is something foolish, but I would really like to know what i did. -- Len The two most common elements in the universe are hydrogen and stupidity. -- Harlan Ellison