help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Troubles in Regular Expression Paradise


From: Len Blanks
Subject: Re: Troubles in Regular Expression Paradise
Date: Tue, 13 May 2014 22:13:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (darwin)

Joost Kremers <joost.m.kremers@gmail.com> writes:

> Len Blanks wrote:
>> (defun now-playing (xml-file)
>>   ;;  (interactive "FFile: ")
>>   (with-temp-buffer
>>     (insert-file-contents xml-file)
>>     (goto-char 1)
>>     (when (re-search-forward (concat 
>> "<title><!\\[CDATA\\[\\([^\\]+\\)\\]></title>"
>>                                   "[\0-\377[:nonascii:]]*"
>>                                   
>> "<artist><!\\[CDATA\\[\\([^\\]+\\)\\]></artist>"
>>                                   "[\0-\377[:nonascii:]]*"
>>                                   
>> "<album><!\\[CDATA\\[\\([^\\]+\\)\\]></album>") 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.
>
> You can only use such substitution operators in functions that are aware
> of them. Normal string-handling functions are not, you'll need something
> like match-string.

Vielen Dank.  I'll try that.
-- 
Len

Science is supposedly the method by which we stand on the shoulders of those who
came before us.  In computer science we are all standing on each others' feet.
                                                                      -- G Popek



reply via email to

[Prev in Thread] Current Thread [Next in Thread]