From: Len Blanks <ltb@haruspex.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Troubles in Regular Expression Paradise
Date: Tue, 13 May 2014 22:13:55 -0500 [thread overview]
Message-ID: <m2iop9qcgc.fsf@haruspex.net> (raw)
In-Reply-To: <slrnln5mqs.377.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> (Joost Kremers's message of "14 May 2014 02:56:28 GMT")
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
next prev parent reply other threads:[~2014-05-14 3:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1280.1400034904.1147.help-gnu-emacs@gnu.org>
2014-05-14 2:56 ` Troubles in Regular Expression Paradise Joost Kremers
2014-05-14 3:13 ` Len Blanks [this message]
2014-05-14 2:18 Len Blanks
2014-05-14 12:40 ` Nicolas Richard
2014-05-14 22:07 ` Len Blanks
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=m2iop9qcgc.fsf@haruspex.net \
--to=ltb@haruspex.net \
--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).