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

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

Re: pattern-identification-data-extraction-format-string


From: Emanuel Berg
Subject: Re: pattern-identification-data-extraction-format-string
Date: Tue, 24 Mar 2015 03:32:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> ... section "Extracting submatches from a regex
> match", so I put together ...
>
> Maybe my original solution to that particular
> problem is just as good, but I asked for a generic
> way and this seems to be it.

Even cooler:

    (defun make-match-list (num string)
      (let ((match (match-string num string)))
        (if match (cons match (make-match-list (1+ num) string) ))))

    (defun match-data-format (data match format-str)
      (save-match-data
        (string-match match data)
        (eval `(message format-str ,@(make-match-list 1 data) ))))

    (match-data-format
     "From: Joe Hacker <get@this.data>"
     "\\(.*\\): *\\(.*[[:alnum:]]\\) *<\\(.*\\)>"
     "header is: %s\nname is: %s\ne-mail is: %s") ; eval me

-- 
underground experts united


reply via email to

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