From: Joost Kremers <joost.m.kremers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Troubles in Regular Expression Paradise
Date: 14 May 2014 02:56:28 GMT [thread overview]
Message-ID: <slrnln5mqs.377.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: mailman.1280.1400034904.1147.help-gnu-emacs@gnu.org
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.
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
next parent reply other threads:[~2014-05-14 2:56 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 ` Joost Kremers [this message]
2014-05-14 3:13 ` Troubles in Regular Expression Paradise Len Blanks
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=slrnln5mqs.377.joost.m.kremers@j.kremers4.news.arnhem.chello.nl \
--to=joost.m.kremers@gmail.com \
--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).